Skip to content

Commit 8ac8e50

Browse files
mcollinaevanlucas
authored andcommitted
crypto: make LazyTransform compabile with Streams1
Makes LazyTransform writable by Streams1 by assigning .writable = true before the actual classes are loaded. Fixes: #12269 PR-URL: #12380 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
1 parent d58fa78 commit 8ac8e50

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

lib/internal/streams/lazy_transform.js

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ module.exports = LazyTransform;
1010

1111
function LazyTransform(options) {
1212
this._options = options;
13+
this.writable = true;
14+
this.readable = true;
1315
}
1416
util.inherits(LazyTransform, stream.Transform);
1517

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const assert = require('assert');
5+
const crypto = require('crypto');
6+
const Stream = require('stream');
7+
const util = require('util');
8+
9+
const hasher1 = crypto.createHash('sha256');
10+
const hasher2 = crypto.createHash('sha256');
11+
12+
// Calculate the expected result.
13+
hasher1.write(Buffer.from('hello world'));
14+
hasher1.end();
15+
16+
const expected = hasher1.read().toString('hex');
17+
18+
function OldStream() {
19+
Stream.call(this);
20+
21+
this.readable = true;
22+
}
23+
util.inherits(OldStream, Stream);
24+
25+
const stream = new OldStream();
26+
27+
stream.pipe(hasher2).on('finish', common.mustCall(function() {
28+
const hash = hasher2.read().toString('hex');
29+
assert.strictEqual(expected, hash);
30+
}));
31+
32+
stream.emit('data', Buffer.from('hello'));
33+
stream.emit('data', Buffer.from(' world'));
34+
stream.emit('end');

0 commit comments

Comments
 (0)