UNPKG

934 BJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.fromBuffer = fromBuffer;
7exports.bufferToHash = bufferToHash;
8
9var _crypto = require('crypto');
10
11var _crypto2 = _interopRequireDefault(_crypto);
12
13var _from = require('from2');
14
15var _from2 = _interopRequireDefault(_from);
16
17function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18
19// TODO publish to npm as `from2-buffer`
20// create a stream from a buffer
21// buffer -> stream
22function fromBuffer(buffer) {
23 // assert.ok(Buffer.isBuffer(buffer))
24
25 return (0, _from2.default)(function (size, next) {
26 if (buffer.length <= 0) {
27 return this.push(null);
28 }
29
30 var chunk = buffer.slice(0, size);
31 buffer = buffer.slice(size);
32
33 next(null, chunk);
34 });
35}
36
37function bufferToHash(buffer) {
38 var hash = _crypto2.default.createHash('sha256');
39 hash.update(buffer);
40 return hash.digest('hex');
41}
\No newline at end of file