sindresorhus / get-stream

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

`inputStream.unpipe` is not a function #17

Closed kevva closed 8 years ago

kevva commented 8 years ago

Some streams that mimics the behaviour of a Readable doesn't implement the full interface which sometimes causes this to throw, e.g. https://github.com/kevva/resize-img/blob/master/index.js#L65. Since we can't enforce everyone to implementing streams correctly I think we should check if unpipe exists before running it.

sindresorhus commented 8 years ago

What streams? I'm torn. What's to say those broken streams doesn't silently break in other ways too. Working around brokenness is a slippery slope.

kevva commented 8 years ago

The one in my link above for example, https://github.com/lukeapage/pngjs#pngpack. It's a stream, though it don't have all the methods that a Readable usually have, https://github.com/lukeapage/pngjs/blob/master/lib/packer-async.js.

I tried to extend it with the unpipe method, but it failed due to some missing props on this.

sindresorhus commented 8 years ago

Hmm, that module seems to subclass Stream itself and not a specific type. Didn't think Stream itself was subclassable, nor what that actually achieves. I guess we could work around it here, but can you also open an issue about it on that module?

kevva commented 8 years ago

I dunno either. In my eyes it looks like an event emitter achieved by using the Stream interface. Maybe it inherits some internal stream stuff too, I don't know. I'll open an issue over there.