1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.fromBuffer = fromBuffer;
|
7 | exports.bufferToHash = bufferToHash;
|
8 |
|
9 | var _crypto = require('crypto');
|
10 |
|
11 | var _crypto2 = _interopRequireDefault(_crypto);
|
12 |
|
13 | var _from = require('from2');
|
14 |
|
15 | var _from2 = _interopRequireDefault(_from);
|
16 |
|
17 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | function fromBuffer(buffer) {
|
23 |
|
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 |
|
37 | function 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 |