jimhigson / oboe.js

A streaming approach to JSON. Oboe.js speeds up web applications by providing parsed objects before the response completes.
http://jimhigson.github.io/oboe.js-website/index.html
Other
4.79k stars 208 forks source link

Fix Stream Detection #214

Open kierangraham opened 4 years ago

kierangraham commented 4 years ago

Fixes an issue where oboe would fail to correctly detect that an object was a stream.

Previously, o instanceof Object was used to do object detection. Based in the info from this StackOverflow post it's more reliable to do something like object !== null && typeof object === "object".

That's the change that this PR makes as in a TypeScript project I'm working on for some reason the isStream method returned false when reading a file from S3 and unzipping it, which returned a DuplexWrapper stream object.

I've tried to create a test case for this but couldn't quite reproduce it properly; even when I create a simple test to check if my stream object is an instanceof Object it turns out to be true. So I'm not entirely sure what's going on specific to this project that makes the streams in Node (12) not an instance of Object.

In any case, this change still fixes my issue even though I don't completely understand why a stream wouldn't be instanceof Object and the method of checking that is improved and causes no other side effects, with the full suite passing.

Maybe someone with more insights can explain what could be happening.

kierangraham commented 4 years ago

@jimhigson would you be able to give this a review? 🙏