-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
stream: validate readable defaultEncoding
PR-URL: #46430 Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Paolo Insogna <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Rafael Gonzaga <[email protected]> Reviewed-By: Robert Nagy <[email protected]>
- Loading branch information
1 parent
85f9b27
commit 63eca7f
Showing
2 changed files
with
46 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const { Readable } = require('stream'); | ||
|
||
{ | ||
assert.throws(() => { | ||
new Readable({ | ||
read: () => {}, | ||
defaultEncoding: 'my invalid encoding', | ||
}); | ||
}, { | ||
code: 'ERR_UNKNOWN_ENCODING', | ||
}); | ||
} | ||
|
||
{ | ||
const r = new Readable({ | ||
read() {}, | ||
defaultEncoding: 'hex' | ||
}); | ||
|
||
r.push('ab'); | ||
|
||
r.on('data', common.mustCall((chunk) => assert.strictEqual(chunk.toString('hex'), 'ab')), 1); | ||
} | ||
|
||
{ | ||
const r = new Readable({ | ||
read() {}, | ||
defaultEncoding: 'hex', | ||
}); | ||
|
||
r.push('xy', 'utf-8'); | ||
|
||
r.on('data', common.mustCall((chunk) => assert.strictEqual(chunk.toString('utf-8'), 'xy')), 1); | ||
} |