From 1626ce22f22ed0568bc2490b3873782f991239f4 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Wed, 17 Aug 2016 15:47:42 -0400 Subject: [PATCH 1/4] fist run at 6.4.0 --- README.md | 2 +- build/build.js | 1 + build/package.json | 1 + doc/stream.md | 52 ++++++++++------------ test/common.js | 25 ++++++++--- test/parallel/test-stream-preprocess.js | 58 +++++++++++++++++++++++++ test/parallel/test-stream-push-order.js | 2 +- test/parallel/test-stream-writev.js | 4 +- test/parallel/test-stream2-writable.js | 6 +-- 9 files changed, 109 insertions(+), 42 deletions(-) create mode 100644 test/parallel/test-stream-preprocess.js diff --git a/README.md b/README.md index 9fb4feaaa1..177e850eb9 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # readable-stream -***Node-core v6.3.1 streams for userland*** [![Build Status](https://travis-ci.org/nodejs/readable-stream.svg?branch=master)](https://travis-ci.org/nodejs/readable-stream) +***Node-core v6.4.0 streams for userland*** [![Build Status](https://travis-ci.org/nodejs/readable-stream.svg?branch=master)](https://travis-ci.org/nodejs/readable-stream) [![NPM](https://nodei.co/npm/readable-stream.png?downloads=true&downloadRank=true)](https://nodei.co/npm/readable-stream/) diff --git a/build/build.js b/build/build.js index 5d25fbb6bc..756050d6f8 100644 --- a/build/build.js +++ b/build/build.js @@ -50,6 +50,7 @@ function processFile (inputLoc, out, replacements) { if (inputLoc.slice(-3) === '.js') { const transformed = babel.transform(data, { plugins: [ + 'transform-es2015-parameters', 'transform-es2015-arrow-functions', 'transform-es2015-block-scoping', 'transform-es2015-template-literals', diff --git a/build/package.json b/build/package.json index bba632559e..9f6ade5fa1 100644 --- a/build/package.json +++ b/build/package.json @@ -8,6 +8,7 @@ "babel-plugin-transform-es2015-arrow-functions": "^6.5.2", "babel-plugin-transform-es2015-block-scoping": "^6.5.0", "babel-plugin-transform-es2015-for-of": "^6.8.0", + "babel-plugin-transform-es2015-parameters": "^6.11.4", "babel-plugin-transform-es2015-shorthand-properties": "^6.8.0", "babel-plugin-transform-es2015-template-literals": "^6.8.0", "bl": "~0.6.0", diff --git a/doc/stream.md b/doc/stream.md index fc269c8e38..4a88ac8fe4 100644 --- a/doc/stream.md +++ b/doc/stream.md @@ -1,6 +1,6 @@ # Stream - Stability: 2 - Stable +> Stability: 2 - Stable A stream is an abstract interface for working with streaming data in Node.js. The `stream` module provides a base API that makes it easy to build objects @@ -20,7 +20,7 @@ const stream = require('stream'); ``` While it is important for all Node.js users to understand how streams works, -the `stream` module itself is most useful for developer's that are creating new +the `stream` module itself is most useful for developers that are creating new types of stream instances. Developer's who are primarily *consuming* stream objects will rarely (if ever) have need to use the `stream` module directly. @@ -343,7 +343,7 @@ The buffered data will be flushed when either the [`stream.uncork()`][] or [`stream.end()`][stream-end] methods are called. The primary intent of `writable.cork()` is to avoid a situation where writing -many small chunks of data to a stream do not cause an backup in the internal +many small chunks of data to a stream do not cause a backup in the internal buffer that would have an adverse impact on performance. In such situations, implementations that implement the `writable._writev()` method can perform buffered writes in a more optimized manner. @@ -411,7 +411,7 @@ If the `writable.cork()` method is called multiple times on a stream, the same number of calls to `writable.uncork()` must be called to flush the buffered data. -``` +```js stream.cork(); stream.write('some '); stream.cork(); @@ -444,7 +444,7 @@ first argument. To reliably detect write errors, add a listener for the The return value indicates whether the written `chunk` was buffered internally and the buffer has exceeded the `highWaterMark` configured when the stream was created. If `false` is returned, further attempts to write data to the stream -should be paused until the `'drain'` event is emitted. +should be paused until the [`'drain'`][] event is emitted. A Writable stream in object mode will always ignore the `encoding` argument. @@ -676,7 +676,7 @@ rr.on('end', () => { The output of running this script is: -``` +```txt $ node test.js readable: null end @@ -1262,7 +1262,7 @@ write succeeded. It is important to note that all calls to `writable.write()` that occur between the time `writable._write()` is called and the `callback` is called will cause the written data to be buffered. Once the `callback` is invoked, the stream will -emit a `'drain'` event. If a stream implementation is capable of processing +emit a [`'drain'`][] event. If a stream implementation is capable of processing multiple chunks of data at once, the `writable._writev()` method should be implemented. @@ -1554,7 +1554,7 @@ class Counter extends Readable { A [Duplex][] stream is one that implements both [Readable][] and [Writable][], such as a TCP socket connection. -Because Javascript does not have support for multiple inheritance, the +Because JavaScript does not have support for multiple inheritance, the `stream.Duplex` class is extended to implement a [Duplex][] stream (as opposed to extending the `stream.Readable` *and* `stream.Writable` classes). @@ -1968,36 +1968,32 @@ readable buffer so there is nothing for a user to consume. [`'end'`]: #stream_event_end [`'finish'`]: #stream_event_finish [`'readable'`]: #stream_event_readable -[`buf.toString(encoding)`]: https://nodejs.org/docs/v6.3.1/api/buffer.html#buffer_buf_tostring_encoding_start_end -[`EventEmitter`]: https://nodejs.org/docs/v6.3.1/api/events.html#events_class_eventemitter -[`process.stderr`]: https://nodejs.org/docs/v6.3.1/api/process.html#process_process_stderr -[`process.stdin`]: https://nodejs.org/docs/v6.3.1/api/process.html#process_process_stdin -[`process.stdout`]: https://nodejs.org/docs/v6.3.1/api/process.html#process_process_stdout +[`EventEmitter`]: https://nodejs.org/docs/v6.4.0/api/events.html#events_class_eventemitter +[`process.stderr`]: https://nodejs.org/docs/v6.4.0/api/process.html#process_process_stderr +[`process.stdin`]: https://nodejs.org/docs/v6.4.0/api/process.html#process_process_stdin +[`process.stdout`]: https://nodejs.org/docs/v6.4.0/api/process.html#process_process_stdout [`stream.cork()`]: #stream_writable_cork [`stream.pipe()`]: #stream_readable_pipe_destination_options [`stream.uncork()`]: #stream_writable_uncork [`stream.unpipe()`]: #stream_readable_unpipe_destination [`stream.wrap()`]: #stream_readable_wrap_stream -[`tls.CryptoStream`]: https://nodejs.org/docs/v6.3.1/api/tls.html#tls_class_cryptostream [API for Stream Consumers]: #stream_api_for_stream_consumers [API for Stream Implementers]: #stream_api_for_stream_implementers -[child process stdin]: https://nodejs.org/docs/v6.3.1/api/child_process.html#child_process_child_stdin -[child process stdout and stderr]: https://nodejs.org/docs/v6.3.1/api/child_process.html#child_process_child_stdout +[child process stdin]: https://nodejs.org/docs/v6.4.0/api/child_process.html#child_process_child_stdin +[child process stdout and stderr]: https://nodejs.org/docs/v6.4.0/api/child_process.html#child_process_child_stdout [Compatibility]: #stream_compatibility_with_older_node_js_versions [crypto]: crypto.html [Duplex]: #stream_class_stream_duplex -[fs read streams]: https://nodejs.org/docs/v6.3.1/api/fs.html#fs_class_fs_readstream -[fs write streams]: https://nodejs.org/docs/v6.3.1/api/fs.html#fs_class_fs_writestream -[`fs.createReadStream()`]: https://nodejs.org/docs/v6.3.1/api/fs.html#fs_fs_createreadstream_path_options -[`fs.createWriteStream()`]: https://nodejs.org/docs/v6.3.1/api/fs.html#fs_fs_createwritestream_path_options -[`net.Socket`]: https://nodejs.org/docs/v6.3.1/api/net.html#net_class_net_socket -[`zlib.createDeflate()`]: https://nodejs.org/docs/v6.3.1/api/zlib.html#zlib_zlib_createdeflate_options -[HTTP requests, on the client]: https://nodejs.org/docs/v6.3.1/api/http.html#http_class_http_clientrequest -[HTTP responses, on the server]: https://nodejs.org/docs/v6.3.1/api/http.html#http_class_http_serverresponse -[http-incoming-message]: https://nodejs.org/docs/v6.3.1/api/http.html#http_class_http_incomingmessage -[Object mode]: #stream_object_mode +[fs read streams]: https://nodejs.org/docs/v6.4.0/api/fs.html#fs_class_fs_readstream +[fs write streams]: https://nodejs.org/docs/v6.4.0/api/fs.html#fs_class_fs_writestream +[`fs.createReadStream()`]: https://nodejs.org/docs/v6.4.0/api/fs.html#fs_fs_createreadstream_path_options +[`fs.createWriteStream()`]: https://nodejs.org/docs/v6.4.0/api/fs.html#fs_fs_createwritestream_path_options +[`net.Socket`]: https://nodejs.org/docs/v6.4.0/api/net.html#net_class_net_socket +[`zlib.createDeflate()`]: https://nodejs.org/docs/v6.4.0/api/zlib.html#zlib_zlib_createdeflate_options +[HTTP requests, on the client]: https://nodejs.org/docs/v6.4.0/api/http.html#http_class_http_clientrequest +[HTTP responses, on the server]: https://nodejs.org/docs/v6.4.0/api/http.html#http_class_http_serverresponse +[http-incoming-message]: https://nodejs.org/docs/v6.4.0/api/http.html#http_class_http_incomingmessage [Readable]: #stream_class_stream_readable -[SimpleProtocol v2]: #stream_example_simpleprotocol_parser_v2 [stream-_flush]: #stream_transform_flush_callback [stream-_read]: #stream_readable_read_size_1 [stream-_transform]: #stream_transform_transform_chunk_encoding_callback @@ -2009,7 +2005,7 @@ readable buffer so there is nothing for a user to consume. [stream-read]: #stream_readable_read_size [stream-resume]: #stream_readable_resume [stream-write]: #stream_writable_write_chunk_encoding_callback -[TCP sockets]: https://nodejs.org/docs/v6.3.1/api/net.html#net_class_net_socket +[TCP sockets]: https://nodejs.org/docs/v6.4.0/api/net.html#net_class_net_socket [Transform]: #stream_class_stream_transform [Writable]: #stream_class_stream_writable [zlib]: zlib.html diff --git a/test/common.js b/test/common.js index 4e933019c8..3307409b0f 100644 --- a/test/common.js +++ b/test/common.js @@ -41,19 +41,21 @@ util.inherits = require('inherits'); var Timer = { now: function () {} }; -var testRoot = path.resolve(process.env.NODE_TEST_DIR || path.dirname(__filename)); +var testRoot = process.env.NODE_TEST_DIR ? path.resolve(process.env.NODE_TEST_DIR) : __dirname; -exports.testDir = path.dirname(__filename); +exports.testDir = __dirname; exports.fixturesDir = path.join(exports.testDir, 'fixtures'); exports.libDir = path.join(exports.testDir, '../lib'); exports.tmpDirName = 'tmp'; exports.PORT = +process.env.NODE_COMMON_PORT || 12346; exports.isWindows = process.platform === 'win32'; -exports.isWOW64 = exports.isWindows && process.env['PROCESSOR_ARCHITEW6432'] !== undefined; +exports.isWOW64 = exports.isWindows && process.env.PROCESSOR_ARCHITEW6432 !== undefined; exports.isAix = process.platform === 'aix'; exports.isLinuxPPCBE = process.platform === 'linux' && process.arch === 'ppc64' && os.endianness() === 'BE'; exports.isSunOS = process.platform === 'sunos'; exports.isFreeBSD = process.platform === 'freebsd'; +exports.isLinux = process.platform === 'linux'; +exports.isOSX = process.platform === 'darwin'; exports.enoughTestMem = os.totalmem() > 0x40000000; /* 1 Gb */ exports.rootDir = exports.isWindows ? 'c:\\' : '/'; @@ -81,7 +83,7 @@ function rmdirSync(p, originalEr) { } catch (e) { if (e.code === 'ENOTDIR') throw originalEr; if (e.code === 'ENOTEMPTY' || e.code === 'EEXIST' || e.code === 'EPERM') { - var enc = process.platform === 'linux' ? 'buffer' : 'utf8'; + var enc = exports.isLinux ? 'buffer' : 'utf8'; fs.readdirSync(p, forEach(enc), function (f) { if (f instanceof Buffer) { var buf = Buffer.concat([Buffer.from(p), Buffer.from(path.sep), f]); @@ -111,7 +113,7 @@ var inFreeBSDJail = null; var localhostIPv4 = null; exports.localIPv6Hosts = ['localhost']; -if (process.platform === 'linux') { +if (exports.isLinux) { exports.localIPv6Hosts = [ // Debian/Ubuntu 'ip6-localhost', 'ip6-loopback', @@ -128,7 +130,7 @@ if (process.platform === 'linux') { get: function () { if (inFreeBSDJail !== null) return inFreeBSDJail; - if (process.platform === 'freebsd' && child_process.execSync('sysctl -n security.jail.jailed').toString() === '1\n') { + if (exports.isFreeBSD && child_process.execSync('sysctl -n security.jail.jailed').toString() === '1\n') { inFreeBSDJail = true; } else { inFreeBSDJail = false; @@ -348,6 +350,15 @@ if (global.Symbol) { knownGlobals.push(Symbol); } +function allowGlobals() { + for (var _len = arguments.length, whitelist = Array(_len), _key = 0; _key < _len; _key++) { + whitelist[_key] = arguments[_key]; + } + + knownGlobals = knownGlobals.concat(whitelist); +} +exports.allowGlobals = allowGlobals; + /**/ if (typeof constructor == 'function') knownGlobals.push(constructor); if (typeof DTRACE_NET_SOCKET_READ == 'function') knownGlobals.push(DTRACE_NET_SOCKET_READ); @@ -479,7 +490,7 @@ exports.nodeProcessAborted = function nodeProcessAborted(exitCode, signal) { // On Windows, v8's base::OS::Abort triggers an access violation, // which corresponds to exit code 3221225477 (0xC0000005) - if (process.platform === 'win32') expectedExitCodes = [3221225477]; + if (exports.isWindows) expectedExitCodes = [3221225477]; // When using --abort-on-uncaught-exception, V8 will use // base::OS::Abort to terminate the process. diff --git a/test/parallel/test-stream-preprocess.js b/test/parallel/test-stream-preprocess.js new file mode 100644 index 0000000000..709de654e5 --- /dev/null +++ b/test/parallel/test-stream-preprocess.js @@ -0,0 +1,58 @@ +/**/ +var bufferShim = require('buffer-shims'); +/**/ +var common = require('../common'); +var assert = require('assert/'); + +var fs = require('fs'); +var path = require('path'); +var rl = require('readline'); + +var BOM = '\uFEFF'; + +// Get the data using a non-stream way to compare with the streamed data. +var modelData = fs.readFileSync(path.join(common.fixturesDir, 'file-to-read-without-bom.txt'), 'utf8'); +var modelDataFirstCharacter = modelData[0]; + +// Detect the number of forthcoming 'line' events for mustCall() 'expected' arg. +var lineCount = modelData.match(/\n/g).length; + +// Ensure both without-bom and with-bom test files are textwise equal. +assert.strictEqual(fs.readFileSync(path.join(common.fixturesDir, 'file-to-read-with-bom.txt'), 'utf8'), '' + BOM + modelData); + +// An unjustified BOM stripping with a non-BOM character unshifted to a stream. +var inputWithoutBOM = fs.createReadStream(path.join(common.fixturesDir, 'file-to-read-without-bom.txt'), 'utf8'); + +inputWithoutBOM.once('readable', common.mustCall(function () { + var maybeBOM = inputWithoutBOM.read(1); + assert.strictEqual(maybeBOM, modelDataFirstCharacter); + assert.notStrictEqual(maybeBOM, BOM); + + inputWithoutBOM.unshift(maybeBOM); + + var streamedData = ''; + rl.createInterface({ + input: inputWithoutBOM + }).on('line', common.mustCall(function (line) { + streamedData += line + '\n'; + }, lineCount)).on('close', common.mustCall(function () { + assert.strictEqual(streamedData, modelData); + })); +})); + +// A justified BOM stripping. +var inputWithBOM = fs.createReadStream(path.join(common.fixturesDir, 'file-to-read-with-bom.txt'), 'utf8'); + +inputWithBOM.once('readable', common.mustCall(function () { + var maybeBOM = inputWithBOM.read(1); + assert.strictEqual(maybeBOM, BOM); + + var streamedData = ''; + rl.createInterface({ + input: inputWithBOM + }).on('line', common.mustCall(function (line) { + streamedData += line + '\n'; + }, lineCount)).on('close', common.mustCall(function () { + assert.strictEqual(streamedData, modelData); + })); +})); \ No newline at end of file diff --git a/test/parallel/test-stream-push-order.js b/test/parallel/test-stream-push-order.js index 39f44ede55..9f4fa15758 100644 --- a/test/parallel/test-stream-push-order.js +++ b/test/parallel/test-stream-push-order.js @@ -30,4 +30,4 @@ s.read(0); process.on('exit', function () { assert.deepStrictEqual(s._readableState.buffer.join(','), '1,2,3,4,5,6'); console.log('ok'); -}); +}); \ No newline at end of file diff --git a/test/parallel/test-stream-writev.js b/test/parallel/test-stream-writev.js index 2088479189..034ccfb14b 100644 --- a/test/parallel/test-stream-writev.js +++ b/test/parallel/test-stream-writev.js @@ -46,7 +46,7 @@ function test(decode, uncork, multi, next) { chunk: [119, 111, 114, 108, 100] }, { encoding: 'buffer', chunk: [33] }, { encoding: 'buffer', chunk: [10, 97, 110, 100, 32, 116, 104, 101, 110, 46, 46, 46] }, { encoding: 'buffer', - chunk: [250, 206, 190, 167, 222, 173, 190, 239, 222, 202, 251, 173] }] : [{ encoding: 'ascii', chunk: 'hello, ' }, { encoding: 'utf8', chunk: 'world' }, { encoding: 'buffer', chunk: [33] }, { encoding: 'binary', chunk: '\nand then...' }, { encoding: 'hex', chunk: 'facebea7deadbeefdecafbad' }]; + chunk: [250, 206, 190, 167, 222, 173, 190, 239, 222, 202, 251, 173] }] : [{ encoding: 'ascii', chunk: 'hello, ' }, { encoding: 'utf8', chunk: 'world' }, { encoding: 'buffer', chunk: [33] }, { encoding: 'latin1', chunk: '\nand then...' }, { encoding: 'hex', chunk: 'facebea7deadbeefdecafbad' }]; var actualChunks; w._writev = function (chunks, cb) { @@ -66,7 +66,7 @@ function test(decode, uncork, multi, next) { if (multi) w.cork(); w.write(bufferShim.from('!'), 'buffer', cnt('!')); - w.write('\nand then...', 'binary', cnt('and then')); + w.write('\nand then...', 'latin1', cnt('and then')); if (multi) w.uncork(); diff --git a/test/parallel/test-stream2-writable.js b/test/parallel/test-stream2-writable.js index 83ecaf6ec2..531e97bc64 100644 --- a/test/parallel/test-stream2-writable.js +++ b/test/parallel/test-stream2-writable.js @@ -133,7 +133,7 @@ test('write bufferize', function (t) { highWaterMark: 100 }); - var encodings = ['hex', 'utf8', 'utf-8', 'ascii', 'binary', 'base64', 'ucs2', 'ucs-2', 'utf16le', 'utf-16le', undefined]; + var encodings = ['hex', 'utf8', 'utf-8', 'ascii', 'latin1', 'binary', 'base64', 'ucs2', 'ucs-2', 'utf16le', 'utf-16le', undefined]; tw.on('finish', function () { t.same(tw.buffer, chunks, 'got the expected chunks'); @@ -159,7 +159,7 @@ test('write no bufferize', function (t) { return TestWriter.prototype._write.call(this, chunk, encoding, cb); }; - var encodings = ['hex', 'utf8', 'utf-8', 'ascii', 'binary', 'base64', 'ucs2', 'ucs-2', 'utf16le', 'utf-16le', undefined]; + var encodings = ['hex', 'utf8', 'utf-8', 'ascii', 'latin1', 'binary', 'base64', 'ucs2', 'ucs-2', 'utf16le', 'utf-16le', undefined]; tw.on('finish', function () { t.same(tw.buffer, chunks, 'got the expected chunks'); @@ -251,7 +251,7 @@ test('encoding should be ignored for buffers', function (t) { t.end(); }; var buf = bufferShim.from(hex, 'hex'); - tw.write(buf, 'binary'); + tw.write(buf, 'latin1'); }); test('writables are not pipable', function (t) { From 613315ead31f3451aa4974e214f259a83da33375 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Wed, 17 Aug 2016 16:30:30 -0400 Subject: [PATCH 2/4] fix tests --- build/test-replacements.js | 10 ++++++++++ package.json | 1 + test/fixtures/file-to-read-with-bom.txt | 3 +++ test/fixtures/file-to-read-without-bom.txt | 3 +++ test/parallel/test-stream-writev.js | 4 ++-- test/parallel/test-stream2-writable.js | 4 ++-- 6 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 test/fixtures/file-to-read-with-bom.txt create mode 100644 test/fixtures/file-to-read-without-bom.txt diff --git a/build/test-replacements.js b/build/test-replacements.js index 33246f3a92..d6ec87c430 100644 --- a/build/test-replacements.js +++ b/build/test-replacements.js @@ -60,6 +60,10 @@ module.exports['test-stream2-transform.js'] = [ module.exports['test-stream2-writable.js'] = [ altForEachImplReplacement , altForEachUseReplacement + , [ + /'latin1',/g, + '\'binary\',' + ] ] module.exports['test-stream-big-packet.js'] = [ @@ -274,3 +278,9 @@ module.exports['test-stream2-readable-from-list.js'] = [ 'require(\'../../lib/internal/streams/BufferList\')' ] ] +module.exports['test-stream-writev.js'] = [ + [ + /'latin1'/g, + `'binary'` + ] +] diff --git a/package.json b/package.json index 42930904e9..a5d2a0bdd7 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "devDependencies": { "assert": "~1.4.0", "babel-polyfill": "^6.9.1", + "buffer": "^4.9.0", "nyc": "^6.4.0", "tap": "~0.7.1", "tape": "~4.5.1", diff --git a/test/fixtures/file-to-read-with-bom.txt b/test/fixtures/file-to-read-with-bom.txt new file mode 100644 index 0000000000..d46c8708d9 --- /dev/null +++ b/test/fixtures/file-to-read-with-bom.txt @@ -0,0 +1,3 @@ +abc +def +ghi diff --git a/test/fixtures/file-to-read-without-bom.txt b/test/fixtures/file-to-read-without-bom.txt new file mode 100644 index 0000000000..8edb37e36d --- /dev/null +++ b/test/fixtures/file-to-read-without-bom.txt @@ -0,0 +1,3 @@ +abc +def +ghi diff --git a/test/parallel/test-stream-writev.js b/test/parallel/test-stream-writev.js index 034ccfb14b..2088479189 100644 --- a/test/parallel/test-stream-writev.js +++ b/test/parallel/test-stream-writev.js @@ -46,7 +46,7 @@ function test(decode, uncork, multi, next) { chunk: [119, 111, 114, 108, 100] }, { encoding: 'buffer', chunk: [33] }, { encoding: 'buffer', chunk: [10, 97, 110, 100, 32, 116, 104, 101, 110, 46, 46, 46] }, { encoding: 'buffer', - chunk: [250, 206, 190, 167, 222, 173, 190, 239, 222, 202, 251, 173] }] : [{ encoding: 'ascii', chunk: 'hello, ' }, { encoding: 'utf8', chunk: 'world' }, { encoding: 'buffer', chunk: [33] }, { encoding: 'latin1', chunk: '\nand then...' }, { encoding: 'hex', chunk: 'facebea7deadbeefdecafbad' }]; + chunk: [250, 206, 190, 167, 222, 173, 190, 239, 222, 202, 251, 173] }] : [{ encoding: 'ascii', chunk: 'hello, ' }, { encoding: 'utf8', chunk: 'world' }, { encoding: 'buffer', chunk: [33] }, { encoding: 'binary', chunk: '\nand then...' }, { encoding: 'hex', chunk: 'facebea7deadbeefdecafbad' }]; var actualChunks; w._writev = function (chunks, cb) { @@ -66,7 +66,7 @@ function test(decode, uncork, multi, next) { if (multi) w.cork(); w.write(bufferShim.from('!'), 'buffer', cnt('!')); - w.write('\nand then...', 'latin1', cnt('and then')); + w.write('\nand then...', 'binary', cnt('and then')); if (multi) w.uncork(); diff --git a/test/parallel/test-stream2-writable.js b/test/parallel/test-stream2-writable.js index 531e97bc64..d695254646 100644 --- a/test/parallel/test-stream2-writable.js +++ b/test/parallel/test-stream2-writable.js @@ -133,7 +133,7 @@ test('write bufferize', function (t) { highWaterMark: 100 }); - var encodings = ['hex', 'utf8', 'utf-8', 'ascii', 'latin1', 'binary', 'base64', 'ucs2', 'ucs-2', 'utf16le', 'utf-16le', undefined]; + var encodings = ['hex', 'utf8', 'utf-8', 'ascii', 'binary', 'binary', 'base64', 'ucs2', 'ucs-2', 'utf16le', 'utf-16le', undefined]; tw.on('finish', function () { t.same(tw.buffer, chunks, 'got the expected chunks'); @@ -159,7 +159,7 @@ test('write no bufferize', function (t) { return TestWriter.prototype._write.call(this, chunk, encoding, cb); }; - var encodings = ['hex', 'utf8', 'utf-8', 'ascii', 'latin1', 'binary', 'base64', 'ucs2', 'ucs-2', 'utf16le', 'utf-16le', undefined]; + var encodings = ['hex', 'utf8', 'utf-8', 'ascii', 'binary', 'binary', 'base64', 'ucs2', 'ucs-2', 'utf16le', 'utf-16le', undefined]; tw.on('finish', function () { t.same(tw.buffer, chunks, 'got the expected chunks'); From a7d02f85c8f3083b740d2df653f1fdcc70d13e52 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Mon, 29 Aug 2016 16:16:49 -0400 Subject: [PATCH 3/4] rm preprocess test --- build/build.js | 2 +- test/parallel/test-stream-preprocess.js | 58 ------------------------- 2 files changed, 1 insertion(+), 59 deletions(-) delete mode 100644 test/parallel/test-stream-preprocess.js diff --git a/build/build.js b/build/build.js index 756050d6f8..2bdbedc57e 100644 --- a/build/build.js +++ b/build/build.js @@ -104,7 +104,7 @@ hyperquest(testlisturl).pipe(bl(function (err, data) { $('table.files .js-navigation-open').each(function () { var file = $(this).text() - if (/^test-stream/.test(file) && !/-wrap(?:-encoding)?\.js$/.test(file) && file !== 'test-stream2-httpclient-response-end.js' && file !== 'test-stream-base-no-abort.js') + if (/^test-stream/.test(file) && !/-wrap(?:-encoding)?\.js$/.test(file) && file !== 'test-stream2-httpclient-response-end.js' && file !== 'test-stream-base-no-abort.js' && file !== 'test-stream-preprocess.js') processTestFile(file) }) })) diff --git a/test/parallel/test-stream-preprocess.js b/test/parallel/test-stream-preprocess.js deleted file mode 100644 index 709de654e5..0000000000 --- a/test/parallel/test-stream-preprocess.js +++ /dev/null @@ -1,58 +0,0 @@ -/**/ -var bufferShim = require('buffer-shims'); -/**/ -var common = require('../common'); -var assert = require('assert/'); - -var fs = require('fs'); -var path = require('path'); -var rl = require('readline'); - -var BOM = '\uFEFF'; - -// Get the data using a non-stream way to compare with the streamed data. -var modelData = fs.readFileSync(path.join(common.fixturesDir, 'file-to-read-without-bom.txt'), 'utf8'); -var modelDataFirstCharacter = modelData[0]; - -// Detect the number of forthcoming 'line' events for mustCall() 'expected' arg. -var lineCount = modelData.match(/\n/g).length; - -// Ensure both without-bom and with-bom test files are textwise equal. -assert.strictEqual(fs.readFileSync(path.join(common.fixturesDir, 'file-to-read-with-bom.txt'), 'utf8'), '' + BOM + modelData); - -// An unjustified BOM stripping with a non-BOM character unshifted to a stream. -var inputWithoutBOM = fs.createReadStream(path.join(common.fixturesDir, 'file-to-read-without-bom.txt'), 'utf8'); - -inputWithoutBOM.once('readable', common.mustCall(function () { - var maybeBOM = inputWithoutBOM.read(1); - assert.strictEqual(maybeBOM, modelDataFirstCharacter); - assert.notStrictEqual(maybeBOM, BOM); - - inputWithoutBOM.unshift(maybeBOM); - - var streamedData = ''; - rl.createInterface({ - input: inputWithoutBOM - }).on('line', common.mustCall(function (line) { - streamedData += line + '\n'; - }, lineCount)).on('close', common.mustCall(function () { - assert.strictEqual(streamedData, modelData); - })); -})); - -// A justified BOM stripping. -var inputWithBOM = fs.createReadStream(path.join(common.fixturesDir, 'file-to-read-with-bom.txt'), 'utf8'); - -inputWithBOM.once('readable', common.mustCall(function () { - var maybeBOM = inputWithBOM.read(1); - assert.strictEqual(maybeBOM, BOM); - - var streamedData = ''; - rl.createInterface({ - input: inputWithBOM - }).on('line', common.mustCall(function (line) { - streamedData += line + '\n'; - }, lineCount)).on('close', common.mustCall(function () { - assert.strictEqual(streamedData, modelData); - })); -})); \ No newline at end of file From 3e8da336ec16f72be5f37c9857fb4fdb8db04944 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Wed, 31 Aug 2016 12:23:09 -0400 Subject: [PATCH 4/4] rm unneded fixtures --- test/fixtures/file-to-read-with-bom.txt | 3 --- test/fixtures/file-to-read-without-bom.txt | 3 --- 2 files changed, 6 deletions(-) delete mode 100644 test/fixtures/file-to-read-with-bom.txt delete mode 100644 test/fixtures/file-to-read-without-bom.txt diff --git a/test/fixtures/file-to-read-with-bom.txt b/test/fixtures/file-to-read-with-bom.txt deleted file mode 100644 index d46c8708d9..0000000000 --- a/test/fixtures/file-to-read-with-bom.txt +++ /dev/null @@ -1,3 +0,0 @@ -abc -def -ghi diff --git a/test/fixtures/file-to-read-without-bom.txt b/test/fixtures/file-to-read-without-bom.txt deleted file mode 100644 index 8edb37e36d..0000000000 --- a/test/fixtures/file-to-read-without-bom.txt +++ /dev/null @@ -1,3 +0,0 @@ -abc -def -ghi