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..2bdbedc57e 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', @@ -103,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/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/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/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/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/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-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-stream2-writable.js b/test/parallel/test-stream2-writable.js index 83ecaf6ec2..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', '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', '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'); @@ -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) {