Skip to content

Commit

Permalink
fist run at 6.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
calvinmetcalf committed Aug 17, 2016
1 parent 7ca6e8e commit 90bf802
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 42 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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/)
Expand Down
1 change: 1 addition & 0 deletions build/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions build/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
52 changes: 24 additions & 28 deletions doc/stream.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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.

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -676,7 +676,7 @@ rr.on('end', () => {

The output of running this script is:

```
```txt
$ node test.js
readable: null
end
Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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).

Expand Down Expand Up @@ -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
Expand All @@ -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
25 changes: 18 additions & 7 deletions test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:\\' : '/';
Expand Down Expand Up @@ -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]);
Expand Down Expand Up @@ -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',
Expand All @@ -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;
Expand Down Expand Up @@ -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;

/*<replacement>*/
if (typeof constructor == 'function') knownGlobals.push(constructor);
if (typeof DTRACE_NET_SOCKET_READ == 'function') knownGlobals.push(DTRACE_NET_SOCKET_READ);
Expand Down Expand Up @@ -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.
Expand Down
58 changes: 58 additions & 0 deletions test/parallel/test-stream-preprocess.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*<replacement>*/
var bufferShim = require('buffer-shims');
/*</replacement>*/
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);
}));
}));
2 changes: 1 addition & 1 deletion test/parallel/test-stream-push-order.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
4 changes: 2 additions & 2 deletions test/parallel/test-stream-writev.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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();

Expand Down
6 changes: 3 additions & 3 deletions test/parallel/test-stream2-writable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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');
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 90bf802

Please sign in to comment.