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‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ module.exports = LazyTransform;
1010

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
'use strict';
2+
3+
constcommon=require('../common');
4+
constassert=require('assert');
5+
constcrypto=require('crypto');
6+
constStream=require('stream');
7+
constutil=require('util');
8+
9+
consthasher1=crypto.createHash('sha256');
10+
consthasher2=crypto.createHash('sha256');
11+
12+
// Calculate the expected result.
13+
hasher1.write(Buffer.from('hello world'));
14+
hasher1.end();
15+
16+
constexpected=hasher1.read().toString('hex');
17+
18+
functionOldStream(){
19+
Stream.call(this);
20+
21+
this.readable=true;
22+
}
23+
util.inherits(OldStream,Stream);
24+
25+
conststream=newOldStream();
26+
27+
stream.pipe(hasher2).on('finish',common.mustCall(function(){
28+
consthash=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)