Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
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.
  • Loading branch information
joyeecheung committed Nov 16, 2018
commit 152a8f6e3d1a1af4245cc408a60975530bacf18b
7 changes: 5 additions & 2 deletions lib/internal/streams/lazy_transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@

const stream = require('stream');
const util = require('util');
const crypto = require('crypto');

const {
getDefaultEncoding
} = require('internal/crypto/util');

module.exports = LazyTransform;

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

if (!this._options || !this._options.defaultEncoding) {
this._writableState.defaultEncoding = crypto.DEFAULT_ENCODING;
this._writableState.defaultEncoding = getDefaultEncoding();
Comment thread
refack marked this conversation as resolved.
}

return this[name];
Expand Down