Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need a smarter check for nodebuffer #139

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

Need a smarter check for nodebuffer #139

humphd opened this issue Jun 6, 2014 · 0 comments
Labels

Comments

@humphd
Copy link
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants