Need a smarter check for nodebuffer #139

Closed
humphd opened this Issue Jun 6, 2014 · 0 comments

Projects

None yet

2 participants

@humphd
Contributor
humphd commented Jun 6, 2014

I'm trying to use JSZip in Filer (https://github.com/js-platform/filer) and running into some issues. I've been moving our code over to use Buffer everywhere vs. Uint8Array for binary data, and with the way browserify augments a Uint8Array as a Buffer (e.g., by adding extra methods to the instance), you can loosen your check on when nodebuffers are supported (currently !process.browser). In a browserify build, Buffer will always be available, either as a native type (node.js) or as an augmented Uint8Array, etc. so in theory you should be able to let callers use nodebuffer no matter what environment they are in. Since you're using browserify, you get this for free, so you might want to consider it.

See https://github.com/feross/buffer

Instead of doing a type check, I'd suggest you look at the methods you need on Buffer, and just see if the passed data object supports what you'll call. Then you shouldn't care whether it's a Buffer or Uint8Array-pretending-to-be-a-Buffer.

@Stuk Stuk added the bug label Jun 25, 2014
@Stuk Stuk closed this in ad3f356 Jul 23, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment