Skip to content

Commit a7c1d09

Browse files
joyeecheungcodebytere
authored andcommitted
stream: do not use crypto.DEFAULT_ENCODING in lazy_transform.js
The default encoding can be retrieved via `require('internal/crypto/util').getDefaultEncoding` instead of the deprecated crypto.DEFAULT_ENCODING which triggers a warning. Background: The require chain goes like this: ``` internal/streams/lazy_transform.js -> crypto.js -> internal/crypto/cipher.js (uses LazyTransform in the global scope) -> internal/streams/lazy_transform.js ``` So when `internal/streams/lazy_transform.js` is required before `lib/crypto.js`, we have a circular dependency and since `internal/crypto/cipher.js` uses destructuring to use LazyTransform we will get an error. And it can also trigger a warning if lazy_transform.js is the first file that touches crypto.DEFAULT_ENCODING. PR-URL: #24396 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Sam Roberts <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent bfde244 commit a7c1d09

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

lib/internal/streams/lazy_transform.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55

66
const stream = require('stream');
77
const util = require('util');
8-
const crypto = require('crypto');
8+
9+
const {
10+
getDefaultEncoding
11+
} = require('internal/crypto/util');
912

1013
module.exports = LazyTransform;
1114

@@ -22,7 +25,7 @@ function makeGetter(name) {
2225
this._writableState.decodeStrings = false;
2326

2427
if (!this._options || !this._options.defaultEncoding) {
25-
this._writableState.defaultEncoding = crypto.DEFAULT_ENCODING;
28+
this._writableState.defaultEncoding = getDefaultEncoding();
2629
}
2730

2831
return this[name];

0 commit comments

Comments
 (0)