node/test/parallel/test-stream-readable-default-encoding.js
Marco Ippolito 63eca7fec0
stream: validate readable defaultEncoding
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>
2023-02-05 23:49:33 +00:00

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);
}