sindresorhus / get-stream

Get a stream as a string, Buffer, ArrayBuffer or array
MIT License
341 stars 33 forks source link

Avoid calling setEncoding on the provided stream. #11

Closed jamestalmage closed 8 years ago

jamestalmage commented 8 years ago

Calling setEncoding on the provided stream affects the data other listeners will see.

This side effect can be avoided by first piping to a PassThrough stream.

kevva commented 8 years ago

Didn't know that streams were somewhat "mutable" in a way. Thought that .pipe() would stay the same no matter what encoding you listen on.

PR looks good :+1:

jamestalmage commented 8 years ago

.pipe() does stay the same regardless of setEncoding.

It's stream.on('data', ...) that is affected.

kevva commented 8 years ago

Oh, then I guess it's what I expected :).