Skip to content

Commit

Permalink
refactor(hash): drop HashStream() (#198)
Browse files Browse the repository at this point in the history
BREAKING CHANGE
  • Loading branch information
curbengh committed Apr 27, 2020
1 parent f90fd44 commit 20ab0be
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 48 deletions.
15 changes: 0 additions & 15 deletions README.md
Expand Up @@ -259,21 +259,6 @@ hash('123456');
// <Buffer 7c 4a 8d 09 ca 37 62 af 61 e5 95 20 94 3d c2 64 94 f8 94 1b>
```

### HashStream()
**\[deprecated\]** use [`createSha1Hash()`](#createsha1hash).

Generates SHA1 hash with a transform stream.

``` js
var stream = new HashStream();

fs.createReadStream('/path/to/file')
.pipe(stream)
.on('finish', function(){
console.log(stream.read());
});
```

### highlight(str, [options])

Syntax highlighting for a code block.
Expand Down
23 changes: 0 additions & 23 deletions lib/hash.js
@@ -1,6 +1,5 @@
'use strict';

const { Transform } = require('stream');
const crypto = require('crypto');

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

/**
* @deprecated
* createHash() is stream class.
*/
function HashStream() {
Transform.call(this);
this._hash = createSha1Hash();
}

require('util').inherits(HashStream, Transform);

HashStream.prototype._transform = function(chunk, enc, callback) {
this._hash.update(chunk);
callback();
};

HashStream.prototype._flush = function(callback) {
this.push(this._hash.digest());
callback();
};

exports.hash = content => {
const hash = createSha1Hash();
hash.update(content);
return hash.digest();
};

exports.HashStream = HashStream;
exports.createSha1Hash = createSha1Hash;
10 changes: 0 additions & 10 deletions test/hash.spec.js
Expand Up @@ -18,16 +18,6 @@ describe('hash', () => {
hash.hash(content).should.eql(sha1(content));
});

it('HashStream', () => {
const content = '123456';
const stream = new hash.HashStream();

stream.write(Buffer.from(content));
stream.end();

stream.read().should.eql(sha1(content));
});

it('createSha1Hash', () => {
const _sha1 = hash.createSha1Hash();
const content = '123456';
Expand Down

0 comments on commit 20ab0be

Please sign in to comment.