173
listenStream(source, {
174
onData: async chunk => {
176
>
// if the decoder is ready, we just write directly
177
>
if (decoder) {
178
target.write(decoder.write(chunk.buffer));
179
}
181
>
// otherwise we need to buffer the data until the stream is ready
182
>
else {
183
>
bufferedChunks.push(chunk);
184
>
bytesBuffered += chunk.byteLength;
185
>
186
>
// buffered enough data for encoding detection, create stream
187
>
if (bytesBuffered >= minBytesRequiredForDetection) {
188
189
// pause stream here until the decoder is ready