Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0a79b2d

Browse filesBrowse files
mcollinaMylesBorins
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 <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
1 parent dac66d5 commit 0a79b2d
Copy full SHA for 0a79b2d

File tree

Expand file treeCollapse file tree

2 files changed

+36
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+36
-0
lines changed
Open diff view settings
Collapse file

‎lib/internal/streams/lazy_transform.js‎

Copy file name to clipboardExpand all lines: lib/internal/streams/lazy_transform.js
+2Lines changed: 2 additions & 0 deletions
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

Collapse file
+34Lines changed: 34 additions & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.