Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(hash): drop HashStream() #198

Merged
merged 1 commit into from Apr 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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