UNPKG

550 BJavaScriptView Raw
1const crypto = require('crypto');
2const from = require('from2');
3
4exports.fromBuffer = function fromBuffer (buffer) {
5 // assert.ok(Buffer.isBuffer(buffer))
6
7 return from(function (size, next) {
8 if (buffer.length <= 0) {
9 return this.push(null);
10 }
11
12 const chunk = buffer.slice(0, size);
13 buffer = buffer.slice(size);
14
15 next(null, chunk);
16 });
17};
18
19exports.bufferToHash = function bufferToHash (buffer) {
20 const hash = crypto.createHash('sha256');
21 hash.update(buffer);
22 return hash.digest('hex');
23};