Skip to content
This repository has been archived by the owner on Dec 6, 2022. It is now read-only.

Commit

Permalink
feat: convert String values to buffers to avoid strange situations in…
Browse files Browse the repository at this point in the history
… the browser (#19)

* feat: convert String values to buffers to avoid strange situations in the browser

* chore: update deps
  • Loading branch information
daviddias authored Dec 11, 2016
1 parent 71133d2 commit 794dade
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@
"multihashes": "^0.3.0"
},
"dependencies": {
"async": "^2.1.4",
"multihashing-async": "^0.3.0"
},
"engines": {
"node": ">=4.0.0"
"node": ">=4.0.0",
"npm": ">=3.0.0"
},
"contributors": [
"David Dias <[email protected]>",
Expand All @@ -55,4 +55,4 @@
"greenkeeperio-bot <[email protected]>",
"npmcdn-to-unpkg-bot <[email protected]>"
]
}
}
8 changes: 8 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ function Block (data) {
throw new Error('Block must be constructed with data')
}

if (typeof data !== 'string' || Buffer.isBuffer(data)) {
throw new Error('data should be Buffer')
}

if (!Buffer.isBuffer(data)) {
data = new Buffer(data)
}

this._cache = {}

data = ensureBuffer(data)
Expand Down

0 comments on commit 794dade

Please sign in to comment.