Skip to content

Commit

Permalink
stream: do not use crypto.DEFAULT_ENCODING in lazy_transform.js
Browse files Browse the repository at this point in the history
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: nodejs#24396
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
  • Loading branch information
joyeecheung authored and refack committed Jan 10, 2019
1 parent 58cf70e commit 17e6c59
Showing 1 changed file with 5 additions and 2 deletions.
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();
}

return this[name];
Expand Down

0 comments on commit 17e6c59

Please sign in to comment.