Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node 8 #290

Merged
merged 2 commits into from
Jun 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# readable-stream

***Node-core v7.0.0 streams for userland*** [![Build Status](https://travis-ci.org/nodejs/readable-stream.svg?branch=master)](https://travis-ci.org/nodejs/readable-stream)
***Node-core v8.1.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 All @@ -18,7 +18,7 @@ npm install --save readable-stream
This package is a mirror of the Streams2 and Streams3 implementations in
Node-core.

Full documentation may be found on the [Node.js website](https://nodejs.org/dist/v7.10.0/docs/api/stream.html).
Full documentation may be found on the [Node.js website](https://nodejs.org/dist/v8.1.0/docs/api/stream.html).

If you want to guarantee a stable streams base, regardless of what version of
Node you, or the users of your libraries are using, use **readable-stream** *only* and avoid the *"stream"* module in Node-core, for background see [this blogpost](http://r.va.gg/2014/06/why-i-dont-use-nodes-core-stream-module.html).
Expand Down
17 changes: 11 additions & 6 deletions build/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const hyperquest = require('hyperquest')
, nodeVersionRegexString = '\\d+\\.\\d+\\.\\d+'
, usageVersionRegex = RegExp('^' + nodeVersionRegexString + '$')
, readmeVersionRegex =
RegExp('((?:Node-core )|(?:https\:\/\/nodejs\.org\/dist\/)v)' + nodeVersionRegexString, 'g')
RegExp('((?:(?:Node-core )|(?:https\:\/\/nodejs\.org\/dist\/))v)' + nodeVersionRegexString, 'g')

, readmePath = path.join(__dirname, '..', 'README.md')
, files = require('./files')
Expand Down Expand Up @@ -49,6 +49,10 @@ function processFile (inputLoc, out, replacements) {
var arg2 = replacement[1]
if (typeof arg2 === 'function')
arg2 = arg2.bind(data)
if (arg2 === undefined) {
console.error('missing second arg for file', inputLoc, replacement)
throw new Error('missing second arg in replacement')
}
data = data.replace(regexp, arg2)
})
if (inputLoc.slice(-3) === '.js') {
Expand All @@ -61,7 +65,9 @@ function processFile (inputLoc, out, replacements) {
'transform-es2015-shorthand-properties',
'transform-es2015-for-of',
'transform-es2015-classes',
'transform-es2015-destructuring'
'transform-es2015-destructuring',
'transform-es2015-computed-properties',
'transform-es2015-spread'
]
})
data = transformed.code
Expand Down Expand Up @@ -113,7 +119,6 @@ pump(
throw err
}


//--------------------------------------------------------------------
// Grab & process files in ../lib/

Expand All @@ -134,7 +139,8 @@ pump(
file !== 'test-stream2-httpclient-response-end.js' &&
file !== 'test-stream-base-no-abort.js' &&
file !== 'test-stream-preprocess.js' &&
file !== 'test-stream-inheritance.js') {
file !== 'test-stream-inheritance.js' &&
file !== 'test-stream-base-typechecking.js') {
processTestFile(file)
}
})
Expand All @@ -145,14 +151,13 @@ pump(
// Grab the nodejs/node test/common.js

processFile(
testsrcurl.replace(/parallel\/$/, 'common.js')
testsrcurl.replace(/parallel\/$/, 'common/index.js')
, path.join(testourroot, '../common.js')
, testReplace['common.js']
)

//--------------------------------------------------------------------
// Update Node version in README

processFile(readmePath, readmePath, [
[readmeVersionRegex, "$1" + nodeVersion]
])
Expand Down
5 changes: 5 additions & 0 deletions build/common-replacements.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ module.exports.altForEachUseReplacement = [
, '$1forEach($2, '
]

module.exports.specialForEachReplacment = [
/(\W)(\[(?:\d\,\s)+\d\])(\.forEach\()/gm
, '$1forEach($2, '
]

module.exports.altIndexOfImplReplacement = [
/$/
, '\nfunction indexOf (xs, x) {\n'
Expand Down
98 changes: 75 additions & 23 deletions build/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ const headRegexp = /(^module.exports = \w+;?)/m
]

, processNextTickImport = [
headRegexp
/^('use strict';)$/m
, `$1

/*<replacement>*/
Expand All @@ -139,8 +139,8 @@ const headRegexp = /(^module.exports = \w+;?)/m
/^const internalUtil = require\('internal\/util'\);/m
, '\n/*<replacement>*/\nconst internalUtil = {\n deprecate: require(\'util-deprecate\')\n};\n'
+ '/*</replacement>*/\n'
],
isNode10 = [
]
, isNode10 = [
headRegexp
, `$1

Expand All @@ -156,7 +156,6 @@ const headRegexp = /(^module.exports = \w+;?)/m
asyncWrite(afterWrite, stream, state, finished, cb);
/*</replacement>*/
}

`
]
, safeBufferFix = [
Expand All @@ -166,29 +165,71 @@ const headRegexp = /(^module.exports = \w+;?)/m
/*</replacement>*/`
]
, internalDirectory = [
/require\('internal\/streams\/BufferList'\)/,
'require(\'./internal/streams/BufferList\')'
/require\('internal\/streams\/([a-zA-z]+)'\)/g,
'require(\'./internal/streams/$1\')'
]
, fixInstanceCheck = [
/if \(typeof Symbol === 'function' && Symbol\.hasInstance\) \{/,
`if (typeof Symbol === 'function' && Symbol.hasInstance && typeof Function.prototype[Symbol.hasInstance] === 'function') {`
]
, removeOnWriteBind = [
/onwrite\.bind\([^)]+?\)/,
`function(er) { onwrite(stream, er); }`
/onwrite\.bind\([^)]+?\)/
, `function(er) { onwrite(stream, er); }`
]
, removeCorkedFinishBind = [
/onCorkedFinish\.bind\([^)]+?\)/,
function (match) {
const code = this
var src = /^function onCorkedFinish[^{]*?\{([\s\S]+?\r?\n)\}/m.exec(code)
src = src[1].trim().replace(/corkReq/g, 'this').replace(/(\r?\n)/mg, ' $1')
return `(err) => {\n${src}\n}`
}
, addUintStuff = [
/const Buffer = require\('buffer'\)\.Buffer;/
, `/*<replacement>*/
const Buffer = require('safe-buffer').Buffer
function _uint8ArrayToBuffer(chunk) {
return Buffer.from(chunk);
}
function _isUint8Array(obj) {
return Object.prototype.toString.call(obj) === '[object Uint8Array]' || Buffer.isBuffer(obj);
}
/*</replacement>*/
`
]
, addConstructors = [
headRegexp
, `$1

/* <replacement> */
function WriteReq(chunk, encoding, cb) {
this.chunk = chunk;
this.encoding = encoding;
this.callback = cb;
this.next = null;
}

// It seems a linked list but it is not
// there will be only 2 of these for each stream
function CorkedRequest(state) {
this.next = null;
this.entry = null;
this.finish = onCorkedFinish.bind(undefined, this, state);
}
/* </replacement> */
`
]
, useWriteReq = [
/state\.lastBufferedRequest = \{.+?\}/g
, `state.lastBufferedRequest = new WriteReq(chunk, encoding, cb)`
]
, useCorkedRequest = [
/var corkReq = [\s\S]+?(.+?)\.corkedRequestsFree = corkReq/g
, `$1.corkedRequestsFree = new CorkedRequest($1)`
]
, fixUintStuff = [
/Stream\.(_isUint8Array|_uint8ArrayToBuffer)\(/g
, `$1(`
]
, removeOnCorkedFinish = [
/^function onCorkedFinish[\s\S]+?\r?\n\}/m,
''
, fixBufferCheck = [
/Object\.getPrototypeOf\((chunk)\) !== Buffer\.prototype/g
, '!Buffer.isBuffer($1)'
]
, fixCopyBuffer = [
/Buffer\.prototype\.copy\.call\(src, target, offset\);/
, 'src.copy(target, offset);'
]

module.exports['_stream_duplex.js'] = [
Expand Down Expand Up @@ -233,8 +274,9 @@ module.exports['_stream_readable.js'] = [
, processNextTickImport
, processNextTickReplacement
, eventEmittterListenerCountReplacement
, safeBufferFix
, internalDirectory
, fixUintStuff
, addUintStuff
]

module.exports['_stream_transform.js'] = [
Expand Down Expand Up @@ -264,12 +306,22 @@ module.exports['_stream_writable.js'] = [
, processNextTickReplacement
, internalUtilReplacement
, fixSyncWrite
, safeBufferFix
, fixInstanceCheck
, removeOnWriteBind
, removeCorkedFinishBind
, removeOnCorkedFinish
, internalDirectory
, fixUintStuff
, addUintStuff
, fixBufferCheck
, useWriteReq
, useCorkedRequest
, addConstructors
]
module.exports['internal/streams/BufferList.js'] = [
safeBufferFix
, fixCopyBuffer

]
module.exports['internal/streams/destroy.js'] = [
processNextTickImport
, processNextTickReplacement
]
2 changes: 2 additions & 0 deletions build/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
"babel-plugin-transform-es2015-arrow-functions": "^6.5.2",
"babel-plugin-transform-es2015-block-scoping": "^6.24.1",
"babel-plugin-transform-es2015-classes": "^6.24.1",
"babel-plugin-transform-es2015-computed-properties": "^6.24.1",
"babel-plugin-transform-es2015-destructuring": "^6.18.0",
"babel-plugin-transform-es2015-for-of": "^6.8.0",
"babel-plugin-transform-es2015-parameters": "^6.24.1",
"babel-plugin-transform-es2015-shorthand-properties": "^6.24.1",
"babel-plugin-transform-es2015-spread": "^6.22.0",
"babel-plugin-transform-es2015-template-literals": "^6.8.0",
"bl": "^1.2.1",
"glob": "^7.1.2",
Expand Down
16 changes: 15 additions & 1 deletion build/test-replacements.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const altForEachImplReplacement = require('./common-replacements').altForEachImp
require('./common-replacements').bufferShimFix
, bufferStaticMethods =
require('./common-replacements').bufferStaticMethods
, specialForEachReplacment =
require('./common-replacements').specialForEachReplacment

module.exports.all = [
[
Expand Down Expand Up @@ -44,7 +46,7 @@ module.exports.all = [

module.exports['test-stream2-basic.js'] = [
altForEachImplReplacement
, altForEachUseReplacement
, specialForEachReplacment
]

module.exports['test-stream2-objects.js'] = [
Expand Down Expand Up @@ -182,6 +184,18 @@ module.exports['common.js'] = [
[
/exports\.buildType/,
'//exports.buildType'
],
[
/require\('async_hooks'\)/,
'/*require(\'async_hooks\')'
],
[
/\}\).enable\(\);/,
'}).enable();*/'
],
[
/const async_wrap = process.binding\('async_wrap'\);/,
'//const async_wrap = process.binding(\'async_wrap\');'
]
]

Expand Down
57 changes: 53 additions & 4 deletions lib/_stream_duplex.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

// a duplex stream is just a stream that is both readable and writable.
// Since JS doesn't have multiple prototypal inheritance, this class
// prototypally inherits from Readable, and then parasitically from
Expand All @@ -7,6 +28,10 @@

/*<replacement>*/

var processNextTick = require('process-nextick-args');
/*</replacement>*/

/*<replacement>*/
var objectKeys = Object.keys || function (obj) {
var keys = [];
for (var key in obj) {
Expand All @@ -17,10 +42,6 @@ var objectKeys = Object.keys || function (obj) {

module.exports = Duplex;

/*<replacement>*/
var processNextTick = require('process-nextick-args');
/*</replacement>*/

/*<replacement>*/
var util = require('core-util-is');
util.inherits = require('inherits');
Expand Down Expand Up @@ -68,6 +89,34 @@ function onEndNT(self) {
self.end();
}

Object.defineProperty(Duplex.prototype, 'destroyed', {
get: function () {
if (this._readableState === undefined || this._writableState === undefined) {
return false;
}
return this._readableState.destroyed && this._writableState.destroyed;
},
set: function (value) {
// we ignore the value if the stream
// has not been initialized yet
if (this._readableState === undefined || this._writableState === undefined) {
return;
}

// backward compatibility, the user is explicitly
// managing destroyed
this._readableState.destroyed = value;
this._writableState.destroyed = value;
}
});

Duplex.prototype._destroy = function (err, cb) {
this.push(null);
this.end();

processNextTick(cb, err);
};

function forEach(xs, f) {
for (var i = 0, l = xs.length; i < l; i++) {
f(xs[i], i);
Expand Down
Loading