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

Support Uin8Array directly in update() #15

Open
webmaster128 opened this issue May 8, 2020 · 1 comment
Open

Support Uin8Array directly in update() #15

webmaster128 opened this issue May 8, 2020 · 1 comment

Comments

@webmaster128
Copy link

Uin8Array is emerging as the standard type for binary data in JavaScript, independent of Node.js's Buffer type. It would be very cool if a user could use Uin8Array input data directly in update() without wrapping it in a Buffer.

Right now this is prevented by an exception

function throwIfNotStringOrBuffer (val, prefix) {
  if (!Buffer.isBuffer(val) && typeof val !== 'string') {
    throw new TypeError(prefix + ' must be a string or a buffer')
  }
}

// ..

HashBase.prototype.update = function (data, encoding) {
  throwIfNotStringOrBuffer(data, 'Data')
  if (this._finalized) throw new Error('Digest already called')
  if (!Buffer.isBuffer(data)) data = Buffer.from(data, encoding)

Here is an Uint8Array type checker for inspiration: https://github.com/iov-one/iov-core/blob/v2.2.4/packages/iov-encoding/src/typechecks.ts#L1-L26

jordaaash added a commit to tendermint/sig that referenced this issue Jun 2, 2020
@jimmywarting
Copy link

Agree, Buffer is bloated/packaged with stuff like the TextEncoder/TextDecoder/DataView solves. Buffer is a huge dependency for browsers

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

No branches or pull requests

2 participants