browserify / browserify/hash-base

Support Uin8Array directly in update()

Open
#15 1 comment 1 reaction 0 assignees View on GitHub
Dominant language
JavaScript
Stars
11
Forks
9
PR merge metrics
No merged PRs in 30d

Description

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

```js
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

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.