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

vs node Buffer #3

Closed
timoxley opened this issue Apr 4, 2014 · 7 comments
Closed

vs node Buffer #3

timoxley opened this issue Apr 4, 2014 · 7 comments
Labels

Comments

@timoxley
Copy link

timoxley commented Apr 4, 2014

There's some similar projects to this that implement node's Buffer api. This means reasonably transparent interoperability with node and one less api to maintain.

This is the one browserify uses afaik https://github.com/feross/buffer

@MidnightLightning
Copy link
Member

Thanks for your comments; yes it appears to be similar to Browserify's implementation, but the intent is different for this module. This module's use in the rest of the cryptocoinjs ecosystem is to standardize the input conversions to various functions (such that a function can just call input = binString(input) and know that input is now a Buffer) without each implementation having to do the if (Array.isArray(input)) ... else if (Buffer.isBuffer(input)) ... logic tree every time.

Beyond that simple use-case with all defaults, the ability to convert between types if you want is useful, and I agree if you're familiar with Buffers there's other ways to do those conversions directly, but this allows for consistency among the project (i.e. even though Buffers do allow ascii as an input format type, that format isn't exposed here, to encourage utf8 instead).

True most of the conversions between different types just use the Node Buffer API, but the one exception of getting an array of byte values out (rather than a Buffer) is valuable since native Node Buffers don't have the join, filter, or map functions Arrays do, so some implementations prefer Arrays, and there's no easy output filter for Buffers to become an Array. Also, the ability to automatically duck-type a string that starts with 0x as a hex-encoded string was very useful for sanitizing certain inputs.

@jprichardson
Copy link
Member

I think binstring can be deprecated. Further discussion here: https://groups.google.com/d/topic/bitcoinhackers/4xkUBnGgQB8/discussion

@sidazhang thoughts?

@shesek
Copy link
Member

shesek commented Apr 14, 2014

I also think that the cryptocoinjs modules should standardize on using Buffer as the uniform input/output format, and have developers do conversions in app-land if needed. I believe that string support must go away (it is too ambiguous, especially with the special 0x prefix handling), but feel less strongly about removing support for byte arrays and Uint8Array (I don't feel its needed and its somewhat cumbersome to handle conversions everywhere, but its ok-ish).

However, I think that binstring might be useful for higher-level code in application land, where it might make more sense to support multiple input formats, as well as a utility for dealing with user-provided input. Though... even for that, I feel that a toBuffer utility that takes multiple input formats and always returns a Buffer might make more sense.

no easy output filter for Buffers to become an Array

Array.apply(null, buff)

@dcousens
Copy link
Contributor

dcousens commented Jan 4, 2017

Deprecated in favour of Buffer?
I got asked this recently, so just cleaning up

@jprichardson
Copy link
Member

Deprecated in favour of Buffer?

Yep, we can safely deprecate this I'd say.

@dcousens
Copy link
Contributor

@jprichardson added notice in ac0f4e0

@dcousens
Copy link
Contributor

Could use a npm deprecate notice though

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

5 participants