mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
54cc7212df
When node began using the OneByte API (f150d56
) it also switched to
officially supporting ISO-8859-1. Though at the time no new encoding
string was introduced.
Introduce the new encoding string 'latin1' to be more explicit. The
previous 'binary' and documented as an alias to 'latin1'. While many
tests have switched to use 'latin1', there are still plenty that do both
'binary' and 'latin1' checks side-by-side to ensure there is no
regression.
PR-URL: https://github.com/nodejs/node/pull/7111
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
35 lines
968 B
JavaScript
35 lines
968 B
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const stream = require('stream');
|
|
const firstEncoding = 'base64';
|
|
const secondEncoding = 'latin1';
|
|
|
|
const examplePath = path.join(common.fixturesDir, 'x.txt');
|
|
const dummyPath = path.join(common.tmpDir, 'x.txt');
|
|
|
|
common.refreshTmpDir();
|
|
|
|
const exampleReadStream = fs.createReadStream(examplePath, {
|
|
encoding: firstEncoding
|
|
});
|
|
|
|
const dummyWriteStream = fs.createWriteStream(dummyPath, {
|
|
encoding: firstEncoding
|
|
});
|
|
|
|
exampleReadStream.pipe(dummyWriteStream).on('finish', function() {
|
|
const assertWriteStream = new stream.Writable({
|
|
write: function(chunk, enc, next) {
|
|
const expected = Buffer.from('xyz\n');
|
|
assert(chunk.equals(expected));
|
|
}
|
|
});
|
|
assertWriteStream.setDefaultEncoding(secondEncoding);
|
|
fs.createReadStream(dummyPath, {
|
|
encoding: secondEncoding
|
|
}).pipe(assertWriteStream);
|
|
});
|