mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
63eca7fec0
PR-URL: https://github.com/nodejs/node/pull/46430 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Paolo Insogna <paolo@cowtech.it> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Robert Nagy <ronagy@icloud.com>
38 lines
696 B
JavaScript
38 lines
696 B
JavaScript
'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);
|
|
}
|