Skip to content

Commit 20ab0be

Browse files
authored
refactor(hash): drop HashStream() (#198)
BREAKING CHANGE
1 parent f90fd44 commit 20ab0be

File tree

3 files changed

+0
-48
lines changed

3 files changed

+0
-48
lines changed

README.md

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -259,21 +259,6 @@ hash('123456');
259259
// <Buffer 7c 4a 8d 09 ca 37 62 af 61 e5 95 20 94 3d c2 64 94 f8 94 1b>
260260
```
261261

262-
### HashStream()
263-
**\[deprecated\]** use [`createSha1Hash()`](#createsha1hash).
264-
265-
Generates SHA1 hash with a transform stream.
266-
267-
``` js
268-
var stream = new HashStream();
269-
270-
fs.createReadStream('/path/to/file')
271-
.pipe(stream)
272-
.on('finish', function(){
273-
console.log(stream.read());
274-
});
275-
```
276-
277262
### highlight(str, [options])
278263

279264
Syntax highlighting for a code block.

lib/hash.js

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use strict';
22

3-
const { Transform } = require('stream');
43
const crypto = require('crypto');
54

65
const ALGORITHM = 'sha1';
@@ -9,32 +8,10 @@ function createSha1Hash() {
98
return crypto.createHash(ALGORITHM);
109
}
1110

12-
/**
13-
* @deprecated
14-
* createHash() is stream class.
15-
*/
16-
function HashStream() {
17-
Transform.call(this);
18-
this._hash = createSha1Hash();
19-
}
20-
21-
require('util').inherits(HashStream, Transform);
22-
23-
HashStream.prototype._transform = function(chunk, enc, callback) {
24-
this._hash.update(chunk);
25-
callback();
26-
};
27-
28-
HashStream.prototype._flush = function(callback) {
29-
this.push(this._hash.digest());
30-
callback();
31-
};
32-
3311
exports.hash = content => {
3412
const hash = createSha1Hash();
3513
hash.update(content);
3614
return hash.digest();
3715
};
3816

39-
exports.HashStream = HashStream;
4017
exports.createSha1Hash = createSha1Hash;

test/hash.spec.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,6 @@ describe('hash', () => {
1818
hash.hash(content).should.eql(sha1(content));
1919
});
2020

21-
it('HashStream', () => {
22-
const content = '123456';
23-
const stream = new hash.HashStream();
24-
25-
stream.write(Buffer.from(content));
26-
stream.end();
27-
28-
stream.read().should.eql(sha1(content));
29-
});
30-
3121
it('createSha1Hash', () => {
3222
const _sha1 = hash.createSha1Hash();
3323
const content = '123456';

0 commit comments

Comments
 (0)