23 if (!\is_resource($stream)) {
24 throw new \TypeError(sprintf(
'Method "%s" takes a stream as a first argument.', __METHOD__));
27 $filter = stream_filter_append($stream,
'convert.base64-encode', STREAM_FILTER_READ, [
28 'line-length' => 0 >= $maxLineLength || 76 < $maxLineLength ? 76 : $maxLineLength,
29 'line-break-chars' =>
"\r\n",
31 if (!\is_resource($filter)) {
32 throw new RuntimeException(
'Unable to set the base64 content encoder to the filter.');
35 if (stream_get_meta_data($stream)[
'seekable'] ??
false) {
38 while (!feof($stream)) {
39 yield fread($stream, 8192);
41 stream_filter_remove($filter);