@contrast/agent 4.32.11 → 4.32.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/node_modules/file-stream-rotator/FileStreamRotator.js +200 -41
- package/node_modules/file-stream-rotator/LICENSE.txt +17 -0
- package/node_modules/file-stream-rotator/README.md +16 -1
- package/node_modules/file-stream-rotator/package.json +5 -5
- package/node_modules/file-stream-rotator/tests/every-minute-test.js +32 -15
- package/node_modules/file-stream-rotator/tests/every-second-test.js +16 -7
- package/node_modules/file-stream-rotator/tests/large-test.js +33 -0
- package/node_modules/file-stream-rotator/tests/rotate-on-size-without-date.js +103 -0
- package/node_modules/object-hash/dist/object_hash.js +1 -2
- package/node_modules/object-hash/index.js +33 -21
- package/node_modules/object-hash/package.json +20 -18
- package/node_modules/object-hash/readme.markdown +20 -5
- package/node_modules/winston-daily-rotate-file/README.md +81 -12
- package/node_modules/winston-daily-rotate-file/daily-rotate-file.js +69 -30
- package/node_modules/winston-daily-rotate-file/index.d.ts +119 -72
- package/node_modules/winston-daily-rotate-file/package.json +20 -19
- package/node_modules/winston-transport/.eslintrc +1 -1
- package/node_modules/winston-transport/.nyc_output/c3d7ddb9-cc26-466b-a4f6-993ad69e86f6.json +1 -0
- package/node_modules/winston-transport/.nyc_output/processinfo/c3d7ddb9-cc26-466b-a4f6-993ad69e86f6.json +1 -0
- package/node_modules/winston-transport/.nyc_output/processinfo/index.json +1 -1
- package/node_modules/winston-transport/CHANGELOG.md +11 -0
- package/node_modules/winston-transport/dist/index.js +2 -2
- package/node_modules/winston-transport/index.d.ts +2 -0
- package/node_modules/winston-transport/index.js +2 -2
- package/node_modules/winston-transport/node_modules/readable-stream/README.md +106 -0
- package/node_modules/winston-transport/node_modules/readable-stream/errors-browser.js +127 -0
- package/node_modules/winston-transport/node_modules/readable-stream/errors.js +116 -0
- package/node_modules/winston-transport/node_modules/readable-stream/experimentalWarning.js +17 -0
- package/node_modules/{readable-stream → winston-transport/node_modules/readable-stream}/lib/_stream_duplex.js +41 -46
- package/node_modules/{readable-stream → winston-transport/node_modules/readable-stream}/lib/_stream_passthrough.js +1 -11
- package/node_modules/{readable-stream → winston-transport/node_modules/readable-stream}/lib/_stream_readable.js +271 -263
- package/node_modules/{readable-stream → winston-transport/node_modules/readable-stream}/lib/_stream_transform.js +18 -42
- package/node_modules/{readable-stream → winston-transport/node_modules/readable-stream}/lib/_stream_writable.js +101 -147
- package/node_modules/winston-transport/node_modules/readable-stream/lib/internal/streams/async_iterator.js +180 -0
- package/node_modules/winston-transport/node_modules/readable-stream/lib/internal/streams/buffer_list.js +183 -0
- package/node_modules/winston-transport/node_modules/readable-stream/lib/internal/streams/destroy.js +96 -0
- package/node_modules/winston-transport/node_modules/readable-stream/lib/internal/streams/end-of-stream.js +86 -0
- package/node_modules/winston-transport/node_modules/readable-stream/lib/internal/streams/from-browser.js +3 -0
- package/node_modules/winston-transport/node_modules/readable-stream/lib/internal/streams/from.js +52 -0
- package/node_modules/winston-transport/node_modules/readable-stream/lib/internal/streams/pipeline.js +86 -0
- package/node_modules/winston-transport/node_modules/readable-stream/lib/internal/streams/state.js +22 -0
- package/node_modules/winston-transport/node_modules/readable-stream/package.json +72 -0
- package/node_modules/{readable-stream → winston-transport/node_modules/readable-stream}/readable-browser.js +2 -0
- package/node_modules/{readable-stream → winston-transport/node_modules/readable-stream}/readable.js +5 -8
- package/node_modules/winston-transport/package.json +16 -14
- package/package.json +6 -6
- package/node_modules/colors/LICENSE +0 -25
- package/node_modules/colors/README.md +0 -221
- package/node_modules/colors/examples/normal-usage.js +0 -82
- package/node_modules/colors/examples/safe-string.js +0 -79
- package/node_modules/colors/index.d.ts +0 -136
- package/node_modules/colors/lib/colors.js +0 -211
- package/node_modules/colors/lib/custom/trap.js +0 -46
- package/node_modules/colors/lib/custom/zalgo.js +0 -110
- package/node_modules/colors/lib/extendStringPrototype.js +0 -110
- package/node_modules/colors/lib/index.js +0 -13
- package/node_modules/colors/lib/maps/america.js +0 -10
- package/node_modules/colors/lib/maps/rainbow.js +0 -12
- package/node_modules/colors/lib/maps/random.js +0 -11
- package/node_modules/colors/lib/maps/zebra.js +0 -5
- package/node_modules/colors/lib/styles.js +0 -95
- package/node_modules/colors/lib/system/has-flag.js +0 -35
- package/node_modules/colors/lib/system/supports-colors.js +0 -151
- package/node_modules/colors/package.json +0 -49
- package/node_modules/colors/safe.d.ts +0 -48
- package/node_modules/colors/safe.js +0 -10
- package/node_modules/colors/themes/generic-logging.js +0 -12
- package/node_modules/core-util-is/LICENSE +0 -19
- package/node_modules/core-util-is/README.md +0 -3
- package/node_modules/core-util-is/float.patch +0 -604
- package/node_modules/core-util-is/lib/util.js +0 -107
- package/node_modules/core-util-is/package.json +0 -36
- package/node_modules/core-util-is/test.js +0 -68
- package/node_modules/cycle/README.md +0 -49
- package/node_modules/cycle/cycle.js +0 -170
- package/node_modules/cycle/package.json +0 -16
- package/node_modules/fast-safe-stringify/.travis.yml +0 -8
- package/node_modules/fast-safe-stringify/CHANGELOG.md +0 -17
- package/node_modules/fast-safe-stringify/LICENSE +0 -23
- package/node_modules/fast-safe-stringify/benchmark.js +0 -137
- package/node_modules/fast-safe-stringify/index.d.ts +0 -8
- package/node_modules/fast-safe-stringify/index.js +0 -161
- package/node_modules/fast-safe-stringify/package.json +0 -50
- package/node_modules/fast-safe-stringify/readme.md +0 -154
- package/node_modules/fast-safe-stringify/test-stable.js +0 -311
- package/node_modules/fast-safe-stringify/test.js +0 -304
- package/node_modules/isarray/.npmignore +0 -1
- package/node_modules/isarray/.travis.yml +0 -4
- package/node_modules/isarray/Makefile +0 -6
- package/node_modules/isarray/README.md +0 -60
- package/node_modules/isarray/component.json +0 -19
- package/node_modules/isarray/index.js +0 -5
- package/node_modules/isarray/package.json +0 -49
- package/node_modules/isarray/test.js +0 -20
- package/node_modules/object-hash/.jshintrc +0 -19
- package/node_modules/object-hash/.travis.yml +0 -35
- package/node_modules/object-hash/bower.json +0 -15
- package/node_modules/object-hash/dist/object_hash.js.map +0 -1
- package/node_modules/object-hash/dist/object_hash_test.js +0 -4737
- package/node_modules/object-hash/gulpfile.js +0 -97
- package/node_modules/object-hash/karma.conf.js +0 -69
- package/node_modules/object-hash/test/blob.js +0 -41
- package/node_modules/object-hash/test/index.js +0 -290
- package/node_modules/object-hash/test/object-classes.js +0 -106
- package/node_modules/object-hash/test/old-crypto.js +0 -60
- package/node_modules/object-hash/test/replacer.js +0 -36
- package/node_modules/object-hash/test/types.js +0 -174
- package/node_modules/object-hash/test/writeToStream.js +0 -27
- package/node_modules/process-nextick-args/index.js +0 -45
- package/node_modules/process-nextick-args/license.md +0 -19
- package/node_modules/process-nextick-args/package.json +0 -29
- package/node_modules/process-nextick-args/readme.md +0 -18
- package/node_modules/readable-stream/.travis.yml +0 -34
- package/node_modules/readable-stream/README.md +0 -58
- package/node_modules/readable-stream/doc/wg-meetings/2015-01-30.md +0 -60
- package/node_modules/readable-stream/duplex-browser.js +0 -1
- package/node_modules/readable-stream/duplex.js +0 -1
- package/node_modules/readable-stream/lib/internal/streams/BufferList.js +0 -79
- package/node_modules/readable-stream/lib/internal/streams/destroy.js +0 -74
- package/node_modules/readable-stream/package.json +0 -56
- package/node_modules/readable-stream/passthrough.js +0 -1
- package/node_modules/readable-stream/transform.js +0 -1
- package/node_modules/readable-stream/writable-browser.js +0 -1
- package/node_modules/readable-stream/writable.js +0 -8
- package/node_modules/winston-compat/.gitattributes +0 -1
- package/node_modules/winston-compat/.node-version +0 -1
- package/node_modules/winston-compat/CHANGELOG.md +0 -17
- package/node_modules/winston-compat/LICENSE +0 -22
- package/node_modules/winston-compat/README.md +0 -2
- package/node_modules/winston-compat/index.js +0 -295
- package/node_modules/winston-compat/lib/transport.js +0 -135
- package/node_modules/winston-compat/node_modules/fecha/CHANGELOG.md +0 -11
- package/node_modules/winston-compat/node_modules/fecha/LICENSE +0 -22
- package/node_modules/winston-compat/node_modules/fecha/README.md +0 -259
- package/node_modules/winston-compat/node_modules/fecha/fecha.d.ts +0 -47
- package/node_modules/winston-compat/node_modules/fecha/fecha.js +0 -334
- package/node_modules/winston-compat/node_modules/fecha/fecha.min.js +0 -1
- package/node_modules/winston-compat/node_modules/fecha/package.json +0 -44
- package/node_modules/winston-compat/node_modules/logform/.babelrc +0 -3
- package/node_modules/winston-compat/node_modules/logform/.eslintrc +0 -7
- package/node_modules/winston-compat/node_modules/logform/.gitattributes +0 -1
- package/node_modules/winston-compat/node_modules/logform/.travis.yml +0 -17
- package/node_modules/winston-compat/node_modules/logform/CHANGELOG.md +0 -103
- package/node_modules/winston-compat/node_modules/logform/LICENSE +0 -21
- package/node_modules/winston-compat/node_modules/logform/README.md +0 -170
- package/node_modules/winston-compat/node_modules/logform/align.js +0 -14
- package/node_modules/winston-compat/node_modules/logform/browser.js +0 -36
- package/node_modules/winston-compat/node_modules/logform/cli.js +0 -52
- package/node_modules/winston-compat/node_modules/logform/colorize.js +0 -118
- package/node_modules/winston-compat/node_modules/logform/combine.js +0 -66
- package/node_modules/winston-compat/node_modules/logform/dist/align.js +0 -14
- package/node_modules/winston-compat/node_modules/logform/dist/browser.js +0 -37
- package/node_modules/winston-compat/node_modules/logform/dist/cli.js +0 -75
- package/node_modules/winston-compat/node_modules/logform/dist/colorize.js +0 -147
- package/node_modules/winston-compat/node_modules/logform/dist/combine.js +0 -66
- package/node_modules/winston-compat/node_modules/logform/dist/format.js +0 -69
- package/node_modules/winston-compat/node_modules/logform/dist/index.js +0 -54
- package/node_modules/winston-compat/node_modules/logform/dist/json.js +0 -27
- package/node_modules/winston-compat/node_modules/logform/dist/label.js +0 -19
- package/node_modules/winston-compat/node_modules/logform/dist/levels.js +0 -15
- package/node_modules/winston-compat/node_modules/logform/dist/logstash.js +0 -32
- package/node_modules/winston-compat/node_modules/logform/dist/metadata.js +0 -63
- package/node_modules/winston-compat/node_modules/logform/dist/ms.js +0 -18
- package/node_modules/winston-compat/node_modules/logform/dist/pad-levels.js +0 -118
- package/node_modules/winston-compat/node_modules/logform/dist/pretty-print.js +0 -20
- package/node_modules/winston-compat/node_modules/logform/dist/printf.js +0 -40
- package/node_modules/winston-compat/node_modules/logform/dist/simple.js +0 -36
- package/node_modules/winston-compat/node_modules/logform/dist/splat.js +0 -147
- package/node_modules/winston-compat/node_modules/logform/dist/timestamp.js +0 -28
- package/node_modules/winston-compat/node_modules/logform/dist/uncolorize.js +0 -31
- package/node_modules/winston-compat/node_modules/logform/examples/combine.js +0 -14
- package/node_modules/winston-compat/node_modules/logform/examples/filter.js +0 -30
- package/node_modules/winston-compat/node_modules/logform/examples/invalid.js +0 -6
- package/node_modules/winston-compat/node_modules/logform/examples/metadata.js +0 -78
- package/node_modules/winston-compat/node_modules/logform/examples/padLevels.js +0 -39
- package/node_modules/winston-compat/node_modules/logform/examples/volume.js +0 -25
- package/node_modules/winston-compat/node_modules/logform/format.js +0 -52
- package/node_modules/winston-compat/node_modules/logform/index.d.ts +0 -53
- package/node_modules/winston-compat/node_modules/logform/index.js +0 -52
- package/node_modules/winston-compat/node_modules/logform/json.js +0 -26
- package/node_modules/winston-compat/node_modules/logform/label.js +0 -19
- package/node_modules/winston-compat/node_modules/logform/levels.js +0 -12
- package/node_modules/winston-compat/node_modules/logform/logstash.js +0 -29
- package/node_modules/winston-compat/node_modules/logform/metadata.js +0 -61
- package/node_modules/winston-compat/node_modules/logform/ms.js +0 -18
- package/node_modules/winston-compat/node_modules/logform/package.json +0 -51
- package/node_modules/winston-compat/node_modules/logform/pad-levels.js +0 -83
- package/node_modules/winston-compat/node_modules/logform/pretty-print.js +0 -16
- package/node_modules/winston-compat/node_modules/logform/printf.js +0 -26
- package/node_modules/winston-compat/node_modules/logform/simple.js +0 -33
- package/node_modules/winston-compat/node_modules/logform/splat.js +0 -125
- package/node_modules/winston-compat/node_modules/logform/timestamp.js +0 -30
- package/node_modules/winston-compat/node_modules/logform/tsconfig.json +0 -22
- package/node_modules/winston-compat/node_modules/logform/uncolorize.js +0 -27
- package/node_modules/winston-compat/package.json +0 -46
- package/node_modules/winston-compat/test/clone.test.js +0 -25
- package/node_modules/winston-compat/test/helpers.js +0 -256
- package/node_modules/winston-compat/test/timestamp.test.js +0 -14
- package/node_modules/winston-compat/test/transports/transport.js +0 -205
- package/node_modules/winston-compat/test/winston-compat.test.js +0 -18
- package/node_modules/winston-daily-rotate-file/.eslintrc.js +0 -11
- package/node_modules/winston-daily-rotate-file/.node-version +0 -1
- package/node_modules/winston-daily-rotate-file/.travis.yml +0 -15
- package/node_modules/winston-daily-rotate-file/node_modules/semver/CHANGELOG.md +0 -70
- package/node_modules/winston-daily-rotate-file/node_modules/semver/LICENSE +0 -15
- package/node_modules/winston-daily-rotate-file/node_modules/semver/README.md +0 -443
- package/node_modules/winston-daily-rotate-file/node_modules/semver/bin/semver.js +0 -174
- package/node_modules/winston-daily-rotate-file/node_modules/semver/package.json +0 -32
- package/node_modules/winston-daily-rotate-file/node_modules/semver/range.bnf +0 -16
- package/node_modules/winston-daily-rotate-file/node_modules/semver/semver.js +0 -1596
- package/node_modules/winston-daily-rotate-file/test/memory-stream.js +0 -38
- package/node_modules/winston-daily-rotate-file/test/random-string.js +0 -31
- package/node_modules/winston-daily-rotate-file/test/transport-tests.js +0 -250
- package/node_modules/winston-transport/.nyc_output/1c69f3e4-4c25-457d-9df5-dfa761729528.json +0 -1
- package/node_modules/winston-transport/.nyc_output/processinfo/1c69f3e4-4c25-457d-9df5-dfa761729528.json +0 -1
- package/node_modules/winston-transport/.travis.yml +0 -17
- package/node_modules/winston-transport/tsconfig.json +0 -22
- /package/node_modules/{readable-stream → winston-transport/node_modules/readable-stream}/CONTRIBUTING.md +0 -0
- /package/node_modules/{readable-stream → winston-transport/node_modules/readable-stream}/GOVERNANCE.md +0 -0
- /package/node_modules/{readable-stream → winston-transport/node_modules/readable-stream}/LICENSE +0 -0
- /package/node_modules/{readable-stream → winston-transport/node_modules/readable-stream}/lib/internal/streams/stream-browser.js +0 -0
- /package/node_modules/{readable-stream → winston-transport/node_modules/readable-stream}/lib/internal/streams/stream.js +0 -0
|
@@ -21,17 +21,8 @@
|
|
|
21
21
|
|
|
22
22
|
'use strict';
|
|
23
23
|
|
|
24
|
-
/*<replacement>*/
|
|
25
|
-
|
|
26
|
-
var pna = require('process-nextick-args');
|
|
27
|
-
/*</replacement>*/
|
|
28
|
-
|
|
29
24
|
module.exports = Readable;
|
|
30
25
|
|
|
31
|
-
/*<replacement>*/
|
|
32
|
-
var isArray = require('isarray');
|
|
33
|
-
/*</replacement>*/
|
|
34
|
-
|
|
35
26
|
/*<replacement>*/
|
|
36
27
|
var Duplex;
|
|
37
28
|
/*</replacement>*/
|
|
@@ -40,8 +31,7 @@ Readable.ReadableState = ReadableState;
|
|
|
40
31
|
|
|
41
32
|
/*<replacement>*/
|
|
42
33
|
var EE = require('events').EventEmitter;
|
|
43
|
-
|
|
44
|
-
var EElistenerCount = function (emitter, type) {
|
|
34
|
+
var EElistenerCount = function EElistenerCount(emitter, type) {
|
|
45
35
|
return emitter.listeners(type).length;
|
|
46
36
|
};
|
|
47
37
|
/*</replacement>*/
|
|
@@ -50,10 +40,8 @@ var EElistenerCount = function (emitter, type) {
|
|
|
50
40
|
var Stream = require('./internal/streams/stream');
|
|
51
41
|
/*</replacement>*/
|
|
52
42
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
var Buffer = require('safe-buffer').Buffer;
|
|
56
|
-
var OurUint8Array = global.Uint8Array || function () {};
|
|
43
|
+
var Buffer = require('buffer').Buffer;
|
|
44
|
+
var OurUint8Array = (typeof global !== 'undefined' ? global : typeof window !== 'undefined' ? window : typeof self !== 'undefined' ? self : {}).Uint8Array || function () {};
|
|
57
45
|
function _uint8ArrayToBuffer(chunk) {
|
|
58
46
|
return Buffer.from(chunk);
|
|
59
47
|
}
|
|
@@ -61,31 +49,33 @@ function _isUint8Array(obj) {
|
|
|
61
49
|
return Buffer.isBuffer(obj) || obj instanceof OurUint8Array;
|
|
62
50
|
}
|
|
63
51
|
|
|
64
|
-
/*</replacement>*/
|
|
65
|
-
|
|
66
|
-
/*<replacement>*/
|
|
67
|
-
var util = Object.create(require('core-util-is'));
|
|
68
|
-
util.inherits = require('inherits');
|
|
69
|
-
/*</replacement>*/
|
|
70
|
-
|
|
71
52
|
/*<replacement>*/
|
|
72
53
|
var debugUtil = require('util');
|
|
73
|
-
var debug
|
|
54
|
+
var debug;
|
|
74
55
|
if (debugUtil && debugUtil.debuglog) {
|
|
75
56
|
debug = debugUtil.debuglog('stream');
|
|
76
57
|
} else {
|
|
77
|
-
debug = function () {};
|
|
58
|
+
debug = function debug() {};
|
|
78
59
|
}
|
|
79
60
|
/*</replacement>*/
|
|
80
61
|
|
|
81
|
-
var BufferList = require('./internal/streams/
|
|
62
|
+
var BufferList = require('./internal/streams/buffer_list');
|
|
82
63
|
var destroyImpl = require('./internal/streams/destroy');
|
|
64
|
+
var _require = require('./internal/streams/state'),
|
|
65
|
+
getHighWaterMark = _require.getHighWaterMark;
|
|
66
|
+
var _require$codes = require('../errors').codes,
|
|
67
|
+
ERR_INVALID_ARG_TYPE = _require$codes.ERR_INVALID_ARG_TYPE,
|
|
68
|
+
ERR_STREAM_PUSH_AFTER_EOF = _require$codes.ERR_STREAM_PUSH_AFTER_EOF,
|
|
69
|
+
ERR_METHOD_NOT_IMPLEMENTED = _require$codes.ERR_METHOD_NOT_IMPLEMENTED,
|
|
70
|
+
ERR_STREAM_UNSHIFT_AFTER_END_EVENT = _require$codes.ERR_STREAM_UNSHIFT_AFTER_END_EVENT;
|
|
71
|
+
|
|
72
|
+
// Lazy loaded to improve the startup performance.
|
|
83
73
|
var StringDecoder;
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
74
|
+
var createReadableStreamAsyncIterator;
|
|
75
|
+
var from;
|
|
76
|
+
require('inherits')(Readable, Stream);
|
|
77
|
+
var errorOrDestroy = destroyImpl.errorOrDestroy;
|
|
87
78
|
var kProxyEvents = ['error', 'close', 'destroy', 'pause', 'resume'];
|
|
88
|
-
|
|
89
79
|
function prependListener(emitter, event, fn) {
|
|
90
80
|
// Sadly this is not cacheable as some libraries bundle their own
|
|
91
81
|
// event emitter implementation with them.
|
|
@@ -95,12 +85,10 @@ function prependListener(emitter, event, fn) {
|
|
|
95
85
|
// userland ones. NEVER DO THIS. This is here only because this code needs
|
|
96
86
|
// to continue to work with older versions of Node.js that do not include
|
|
97
87
|
// the prependListener() method. The goal is to eventually remove this hack.
|
|
98
|
-
if (!emitter._events || !emitter._events[event]) emitter.on(event, fn);else if (isArray(emitter._events[event])) emitter._events[event].unshift(fn);else emitter._events[event] = [fn, emitter._events[event]];
|
|
88
|
+
if (!emitter._events || !emitter._events[event]) emitter.on(event, fn);else if (Array.isArray(emitter._events[event])) emitter._events[event].unshift(fn);else emitter._events[event] = [fn, emitter._events[event]];
|
|
99
89
|
}
|
|
100
|
-
|
|
101
|
-
function ReadableState(options, stream) {
|
|
90
|
+
function ReadableState(options, stream, isDuplex) {
|
|
102
91
|
Duplex = Duplex || require('./_stream_duplex');
|
|
103
|
-
|
|
104
92
|
options = options || {};
|
|
105
93
|
|
|
106
94
|
// Duplex streams are both readable and writable, but share
|
|
@@ -108,24 +96,16 @@ function ReadableState(options, stream) {
|
|
|
108
96
|
// However, some cases require setting options to different
|
|
109
97
|
// values for the readable and the writable sides of the duplex stream.
|
|
110
98
|
// These options can be provided separately as readableXXX and writableXXX.
|
|
111
|
-
|
|
99
|
+
if (typeof isDuplex !== 'boolean') isDuplex = stream instanceof Duplex;
|
|
112
100
|
|
|
113
101
|
// object stream flag. Used to make read(n) ignore n and to
|
|
114
102
|
// make all the buffer merging and length checks go away
|
|
115
103
|
this.objectMode = !!options.objectMode;
|
|
116
|
-
|
|
117
104
|
if (isDuplex) this.objectMode = this.objectMode || !!options.readableObjectMode;
|
|
118
105
|
|
|
119
106
|
// the point at which it stops calling _read() to fill the buffer
|
|
120
107
|
// Note: 0 is a valid value, means "don't call _read preemptively ever"
|
|
121
|
-
|
|
122
|
-
var readableHwm = options.readableHighWaterMark;
|
|
123
|
-
var defaultHwm = this.objectMode ? 16 : 16 * 1024;
|
|
124
|
-
|
|
125
|
-
if (hwm || hwm === 0) this.highWaterMark = hwm;else if (isDuplex && (readableHwm || readableHwm === 0)) this.highWaterMark = readableHwm;else this.highWaterMark = defaultHwm;
|
|
126
|
-
|
|
127
|
-
// cast to ints.
|
|
128
|
-
this.highWaterMark = Math.floor(this.highWaterMark);
|
|
108
|
+
this.highWaterMark = getHighWaterMark(this, options, 'readableHighWaterMark', isDuplex);
|
|
129
109
|
|
|
130
110
|
// A linked list is used to store data chunks instead of an array because the
|
|
131
111
|
// linked list can remove elements from the beginning faster than
|
|
@@ -151,6 +131,13 @@ function ReadableState(options, stream) {
|
|
|
151
131
|
this.emittedReadable = false;
|
|
152
132
|
this.readableListening = false;
|
|
153
133
|
this.resumeScheduled = false;
|
|
134
|
+
this.paused = true;
|
|
135
|
+
|
|
136
|
+
// Should close be emitted on destroy. Defaults to true.
|
|
137
|
+
this.emitClose = options.emitClose !== false;
|
|
138
|
+
|
|
139
|
+
// Should .destroy() be called after 'end' (and potentially 'finish')
|
|
140
|
+
this.autoDestroy = !!options.autoDestroy;
|
|
154
141
|
|
|
155
142
|
// has it been destroyed
|
|
156
143
|
this.destroyed = false;
|
|
@@ -165,7 +152,6 @@ function ReadableState(options, stream) {
|
|
|
165
152
|
|
|
166
153
|
// if true, a maybeReadMore has been scheduled
|
|
167
154
|
this.readingMore = false;
|
|
168
|
-
|
|
169
155
|
this.decoder = null;
|
|
170
156
|
this.encoding = null;
|
|
171
157
|
if (options.encoding) {
|
|
@@ -174,34 +160,35 @@ function ReadableState(options, stream) {
|
|
|
174
160
|
this.encoding = options.encoding;
|
|
175
161
|
}
|
|
176
162
|
}
|
|
177
|
-
|
|
178
163
|
function Readable(options) {
|
|
179
164
|
Duplex = Duplex || require('./_stream_duplex');
|
|
180
|
-
|
|
181
165
|
if (!(this instanceof Readable)) return new Readable(options);
|
|
182
166
|
|
|
183
|
-
|
|
167
|
+
// Checking for a Stream.Duplex instance is faster here instead of inside
|
|
168
|
+
// the ReadableState constructor, at least with V8 6.5
|
|
169
|
+
var isDuplex = this instanceof Duplex;
|
|
170
|
+
this._readableState = new ReadableState(options, this, isDuplex);
|
|
184
171
|
|
|
185
172
|
// legacy
|
|
186
173
|
this.readable = true;
|
|
187
|
-
|
|
188
174
|
if (options) {
|
|
189
175
|
if (typeof options.read === 'function') this._read = options.read;
|
|
190
|
-
|
|
191
176
|
if (typeof options.destroy === 'function') this._destroy = options.destroy;
|
|
192
177
|
}
|
|
193
|
-
|
|
194
178
|
Stream.call(this);
|
|
195
179
|
}
|
|
196
|
-
|
|
197
180
|
Object.defineProperty(Readable.prototype, 'destroyed', {
|
|
198
|
-
|
|
181
|
+
// making it explicit this property is not enumerable
|
|
182
|
+
// because otherwise some prototype manipulation in
|
|
183
|
+
// userland will fail
|
|
184
|
+
enumerable: false,
|
|
185
|
+
get: function get() {
|
|
199
186
|
if (this._readableState === undefined) {
|
|
200
187
|
return false;
|
|
201
188
|
}
|
|
202
189
|
return this._readableState.destroyed;
|
|
203
190
|
},
|
|
204
|
-
set: function (value) {
|
|
191
|
+
set: function set(value) {
|
|
205
192
|
// we ignore the value if the stream
|
|
206
193
|
// has not been initialized yet
|
|
207
194
|
if (!this._readableState) {
|
|
@@ -213,11 +200,9 @@ Object.defineProperty(Readable.prototype, 'destroyed', {
|
|
|
213
200
|
this._readableState.destroyed = value;
|
|
214
201
|
}
|
|
215
202
|
});
|
|
216
|
-
|
|
217
203
|
Readable.prototype.destroy = destroyImpl.destroy;
|
|
218
204
|
Readable.prototype._undestroy = destroyImpl.undestroy;
|
|
219
205
|
Readable.prototype._destroy = function (err, cb) {
|
|
220
|
-
this.push(null);
|
|
221
206
|
cb(err);
|
|
222
207
|
};
|
|
223
208
|
|
|
@@ -228,7 +213,6 @@ Readable.prototype._destroy = function (err, cb) {
|
|
|
228
213
|
Readable.prototype.push = function (chunk, encoding) {
|
|
229
214
|
var state = this._readableState;
|
|
230
215
|
var skipChunkCheck;
|
|
231
|
-
|
|
232
216
|
if (!state.objectMode) {
|
|
233
217
|
if (typeof chunk === 'string') {
|
|
234
218
|
encoding = encoding || state.defaultEncoding;
|
|
@@ -241,7 +225,6 @@ Readable.prototype.push = function (chunk, encoding) {
|
|
|
241
225
|
} else {
|
|
242
226
|
skipChunkCheck = true;
|
|
243
227
|
}
|
|
244
|
-
|
|
245
228
|
return readableAddChunk(this, chunk, encoding, false, skipChunkCheck);
|
|
246
229
|
};
|
|
247
230
|
|
|
@@ -249,8 +232,8 @@ Readable.prototype.push = function (chunk, encoding) {
|
|
|
249
232
|
Readable.prototype.unshift = function (chunk) {
|
|
250
233
|
return readableAddChunk(this, chunk, null, true, false);
|
|
251
234
|
};
|
|
252
|
-
|
|
253
235
|
function readableAddChunk(stream, chunk, encoding, addToFront, skipChunkCheck) {
|
|
236
|
+
debug('readableAddChunk', chunk);
|
|
254
237
|
var state = stream._readableState;
|
|
255
238
|
if (chunk === null) {
|
|
256
239
|
state.reading = false;
|
|
@@ -259,16 +242,17 @@ function readableAddChunk(stream, chunk, encoding, addToFront, skipChunkCheck) {
|
|
|
259
242
|
var er;
|
|
260
243
|
if (!skipChunkCheck) er = chunkInvalid(state, chunk);
|
|
261
244
|
if (er) {
|
|
262
|
-
stream
|
|
245
|
+
errorOrDestroy(stream, er);
|
|
263
246
|
} else if (state.objectMode || chunk && chunk.length > 0) {
|
|
264
247
|
if (typeof chunk !== 'string' && !state.objectMode && Object.getPrototypeOf(chunk) !== Buffer.prototype) {
|
|
265
248
|
chunk = _uint8ArrayToBuffer(chunk);
|
|
266
249
|
}
|
|
267
|
-
|
|
268
250
|
if (addToFront) {
|
|
269
|
-
if (state.endEmitted) stream
|
|
251
|
+
if (state.endEmitted) errorOrDestroy(stream, new ERR_STREAM_UNSHIFT_AFTER_END_EVENT());else addChunk(stream, state, chunk, true);
|
|
270
252
|
} else if (state.ended) {
|
|
271
|
-
stream
|
|
253
|
+
errorOrDestroy(stream, new ERR_STREAM_PUSH_AFTER_EOF());
|
|
254
|
+
} else if (state.destroyed) {
|
|
255
|
+
return false;
|
|
272
256
|
} else {
|
|
273
257
|
state.reading = false;
|
|
274
258
|
if (state.decoder && !encoding) {
|
|
@@ -280,45 +264,34 @@ function readableAddChunk(stream, chunk, encoding, addToFront, skipChunkCheck) {
|
|
|
280
264
|
}
|
|
281
265
|
} else if (!addToFront) {
|
|
282
266
|
state.reading = false;
|
|
267
|
+
maybeReadMore(stream, state);
|
|
283
268
|
}
|
|
284
269
|
}
|
|
285
270
|
|
|
286
|
-
|
|
271
|
+
// We can push more data if we are below the highWaterMark.
|
|
272
|
+
// Also, if we have no data yet, we can stand some more bytes.
|
|
273
|
+
// This is to work around cases where hwm=0, such as the repl.
|
|
274
|
+
return !state.ended && (state.length < state.highWaterMark || state.length === 0);
|
|
287
275
|
}
|
|
288
|
-
|
|
289
276
|
function addChunk(stream, state, chunk, addToFront) {
|
|
290
277
|
if (state.flowing && state.length === 0 && !state.sync) {
|
|
278
|
+
state.awaitDrain = 0;
|
|
291
279
|
stream.emit('data', chunk);
|
|
292
|
-
stream.read(0);
|
|
293
280
|
} else {
|
|
294
281
|
// update the buffer info.
|
|
295
282
|
state.length += state.objectMode ? 1 : chunk.length;
|
|
296
283
|
if (addToFront) state.buffer.unshift(chunk);else state.buffer.push(chunk);
|
|
297
|
-
|
|
298
284
|
if (state.needReadable) emitReadable(stream);
|
|
299
285
|
}
|
|
300
286
|
maybeReadMore(stream, state);
|
|
301
287
|
}
|
|
302
|
-
|
|
303
288
|
function chunkInvalid(state, chunk) {
|
|
304
289
|
var er;
|
|
305
290
|
if (!_isUint8Array(chunk) && typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) {
|
|
306
|
-
er = new
|
|
291
|
+
er = new ERR_INVALID_ARG_TYPE('chunk', ['string', 'Buffer', 'Uint8Array'], chunk);
|
|
307
292
|
}
|
|
308
293
|
return er;
|
|
309
294
|
}
|
|
310
|
-
|
|
311
|
-
// if it's past the high water mark, we can push in some more.
|
|
312
|
-
// Also, if we have no data yet, we can stand some
|
|
313
|
-
// more bytes. This is to work around cases where hwm=0,
|
|
314
|
-
// such as the repl. Also, if the push() triggered a
|
|
315
|
-
// readable event, and the user called read(largeNumber) such that
|
|
316
|
-
// needReadable was set, then we ought to push more, so that another
|
|
317
|
-
// 'readable' event will be triggered.
|
|
318
|
-
function needMoreData(state) {
|
|
319
|
-
return !state.ended && (state.needReadable || state.length < state.highWaterMark || state.length === 0);
|
|
320
|
-
}
|
|
321
|
-
|
|
322
295
|
Readable.prototype.isPaused = function () {
|
|
323
296
|
return this._readableState.flowing === false;
|
|
324
297
|
};
|
|
@@ -326,15 +299,29 @@ Readable.prototype.isPaused = function () {
|
|
|
326
299
|
// backwards compatibility.
|
|
327
300
|
Readable.prototype.setEncoding = function (enc) {
|
|
328
301
|
if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder;
|
|
329
|
-
|
|
330
|
-
this._readableState.
|
|
302
|
+
var decoder = new StringDecoder(enc);
|
|
303
|
+
this._readableState.decoder = decoder;
|
|
304
|
+
// If setEncoding(null), decoder.encoding equals utf8
|
|
305
|
+
this._readableState.encoding = this._readableState.decoder.encoding;
|
|
306
|
+
|
|
307
|
+
// Iterate over current buffer to convert already stored Buffers:
|
|
308
|
+
var p = this._readableState.buffer.head;
|
|
309
|
+
var content = '';
|
|
310
|
+
while (p !== null) {
|
|
311
|
+
content += decoder.write(p.data);
|
|
312
|
+
p = p.next;
|
|
313
|
+
}
|
|
314
|
+
this._readableState.buffer.clear();
|
|
315
|
+
if (content !== '') this._readableState.buffer.push(content);
|
|
316
|
+
this._readableState.length = content.length;
|
|
331
317
|
return this;
|
|
332
318
|
};
|
|
333
319
|
|
|
334
|
-
// Don't raise the hwm >
|
|
335
|
-
var MAX_HWM =
|
|
320
|
+
// Don't raise the hwm > 1GB
|
|
321
|
+
var MAX_HWM = 0x40000000;
|
|
336
322
|
function computeNewHighWaterMark(n) {
|
|
337
323
|
if (n >= MAX_HWM) {
|
|
324
|
+
// TODO(ronag): Throw ERR_VALUE_OUT_OF_RANGE.
|
|
338
325
|
n = MAX_HWM;
|
|
339
326
|
} else {
|
|
340
327
|
// Get the next highest power of 2 to prevent increasing hwm excessively in
|
|
@@ -376,18 +363,16 @@ Readable.prototype.read = function (n) {
|
|
|
376
363
|
n = parseInt(n, 10);
|
|
377
364
|
var state = this._readableState;
|
|
378
365
|
var nOrig = n;
|
|
379
|
-
|
|
380
366
|
if (n !== 0) state.emittedReadable = false;
|
|
381
367
|
|
|
382
368
|
// if we're doing read(0) to trigger a readable event, but we
|
|
383
369
|
// already have a bunch of data in the buffer, then just trigger
|
|
384
370
|
// the 'readable' event and move on.
|
|
385
|
-
if (n === 0 && state.needReadable && (state.length >= state.highWaterMark || state.ended)) {
|
|
371
|
+
if (n === 0 && state.needReadable && ((state.highWaterMark !== 0 ? state.length >= state.highWaterMark : state.length > 0) || state.ended)) {
|
|
386
372
|
debug('read: emitReadable', state.length, state.ended);
|
|
387
373
|
if (state.length === 0 && state.ended) endReadable(this);else emitReadable(this);
|
|
388
374
|
return null;
|
|
389
375
|
}
|
|
390
|
-
|
|
391
376
|
n = howMuchToRead(n, state);
|
|
392
377
|
|
|
393
378
|
// if we've ended, and we're now clear, then finish it up.
|
|
@@ -446,17 +431,15 @@ Readable.prototype.read = function (n) {
|
|
|
446
431
|
// and we need to re-evaluate how much data we can return to the user.
|
|
447
432
|
if (!state.reading) n = howMuchToRead(nOrig, state);
|
|
448
433
|
}
|
|
449
|
-
|
|
450
434
|
var ret;
|
|
451
435
|
if (n > 0) ret = fromList(n, state);else ret = null;
|
|
452
|
-
|
|
453
436
|
if (ret === null) {
|
|
454
|
-
state.needReadable =
|
|
437
|
+
state.needReadable = state.length <= state.highWaterMark;
|
|
455
438
|
n = 0;
|
|
456
439
|
} else {
|
|
457
440
|
state.length -= n;
|
|
441
|
+
state.awaitDrain = 0;
|
|
458
442
|
}
|
|
459
|
-
|
|
460
443
|
if (state.length === 0) {
|
|
461
444
|
// If we have nothing in the buffer, then we want to know
|
|
462
445
|
// as soon as we *do* get something into the buffer.
|
|
@@ -465,13 +448,11 @@ Readable.prototype.read = function (n) {
|
|
|
465
448
|
// If we tried to read() past the EOF, then emit end on the next tick.
|
|
466
449
|
if (nOrig !== n && state.ended) endReadable(this);
|
|
467
450
|
}
|
|
468
|
-
|
|
469
451
|
if (ret !== null) this.emit('data', ret);
|
|
470
|
-
|
|
471
452
|
return ret;
|
|
472
453
|
};
|
|
473
|
-
|
|
474
454
|
function onEofChunk(stream, state) {
|
|
455
|
+
debug('onEofChunk');
|
|
475
456
|
if (state.ended) return;
|
|
476
457
|
if (state.decoder) {
|
|
477
458
|
var chunk = state.decoder.end();
|
|
@@ -481,9 +462,19 @@ function onEofChunk(stream, state) {
|
|
|
481
462
|
}
|
|
482
463
|
}
|
|
483
464
|
state.ended = true;
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
465
|
+
if (state.sync) {
|
|
466
|
+
// if we are sync, wait until next tick to emit the data.
|
|
467
|
+
// Otherwise we risk emitting data in the flow()
|
|
468
|
+
// the readable code triggers during a read() call
|
|
469
|
+
emitReadable(stream);
|
|
470
|
+
} else {
|
|
471
|
+
// emit 'readable' now to make sure it gets picked up.
|
|
472
|
+
state.needReadable = false;
|
|
473
|
+
if (!state.emittedReadable) {
|
|
474
|
+
state.emittedReadable = true;
|
|
475
|
+
emitReadable_(stream);
|
|
476
|
+
}
|
|
477
|
+
}
|
|
487
478
|
}
|
|
488
479
|
|
|
489
480
|
// Don't emit readable right away in sync mode, because this can trigger
|
|
@@ -491,17 +482,29 @@ function onEofChunk(stream, state) {
|
|
|
491
482
|
// a nextTick recursion warning, but that's not so bad.
|
|
492
483
|
function emitReadable(stream) {
|
|
493
484
|
var state = stream._readableState;
|
|
485
|
+
debug('emitReadable', state.needReadable, state.emittedReadable);
|
|
494
486
|
state.needReadable = false;
|
|
495
487
|
if (!state.emittedReadable) {
|
|
496
488
|
debug('emitReadable', state.flowing);
|
|
497
489
|
state.emittedReadable = true;
|
|
498
|
-
|
|
490
|
+
process.nextTick(emitReadable_, stream);
|
|
499
491
|
}
|
|
500
492
|
}
|
|
501
|
-
|
|
502
493
|
function emitReadable_(stream) {
|
|
503
|
-
|
|
504
|
-
|
|
494
|
+
var state = stream._readableState;
|
|
495
|
+
debug('emitReadable_', state.destroyed, state.length, state.ended);
|
|
496
|
+
if (!state.destroyed && (state.length || state.ended)) {
|
|
497
|
+
stream.emit('readable');
|
|
498
|
+
state.emittedReadable = false;
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
// The stream needs another readable event if
|
|
502
|
+
// 1. It is not flowing, as the flow mechanism will take
|
|
503
|
+
// care of it.
|
|
504
|
+
// 2. It is not ended.
|
|
505
|
+
// 3. It is below the highWaterMark, so we can schedule
|
|
506
|
+
// another readable later.
|
|
507
|
+
state.needReadable = !state.flowing && !state.ended && state.length <= state.highWaterMark;
|
|
505
508
|
flow(stream);
|
|
506
509
|
}
|
|
507
510
|
|
|
@@ -514,18 +517,40 @@ function emitReadable_(stream) {
|
|
|
514
517
|
function maybeReadMore(stream, state) {
|
|
515
518
|
if (!state.readingMore) {
|
|
516
519
|
state.readingMore = true;
|
|
517
|
-
|
|
520
|
+
process.nextTick(maybeReadMore_, stream, state);
|
|
518
521
|
}
|
|
519
522
|
}
|
|
520
|
-
|
|
521
523
|
function maybeReadMore_(stream, state) {
|
|
522
|
-
|
|
523
|
-
|
|
524
|
+
// Attempt to read more data if we should.
|
|
525
|
+
//
|
|
526
|
+
// The conditions for reading more data are (one of):
|
|
527
|
+
// - Not enough data buffered (state.length < state.highWaterMark). The loop
|
|
528
|
+
// is responsible for filling the buffer with enough data if such data
|
|
529
|
+
// is available. If highWaterMark is 0 and we are not in the flowing mode
|
|
530
|
+
// we should _not_ attempt to buffer any extra data. We'll get more data
|
|
531
|
+
// when the stream consumer calls read() instead.
|
|
532
|
+
// - No data in the buffer, and the stream is in flowing mode. In this mode
|
|
533
|
+
// the loop below is responsible for ensuring read() is called. Failing to
|
|
534
|
+
// call read here would abort the flow and there's no other mechanism for
|
|
535
|
+
// continuing the flow if the stream consumer has just subscribed to the
|
|
536
|
+
// 'data' event.
|
|
537
|
+
//
|
|
538
|
+
// In addition to the above conditions to keep reading data, the following
|
|
539
|
+
// conditions prevent the data from being read:
|
|
540
|
+
// - The stream has ended (state.ended).
|
|
541
|
+
// - There is already a pending 'read' operation (state.reading). This is a
|
|
542
|
+
// case where the the stream has called the implementation defined _read()
|
|
543
|
+
// method, but they are processing the call asynchronously and have _not_
|
|
544
|
+
// called push() with new data. In this case we skip performing more
|
|
545
|
+
// read()s. The execution ends in this method again after the _read() ends
|
|
546
|
+
// up calling push() with more data.
|
|
547
|
+
while (!state.reading && !state.ended && (state.length < state.highWaterMark || state.flowing && state.length === 0)) {
|
|
548
|
+
var len = state.length;
|
|
524
549
|
debug('maybeReadMore read 0');
|
|
525
550
|
stream.read(0);
|
|
526
551
|
if (len === state.length)
|
|
527
552
|
// didn't get any data, stop spinning.
|
|
528
|
-
break;
|
|
553
|
+
break;
|
|
529
554
|
}
|
|
530
555
|
state.readingMore = false;
|
|
531
556
|
}
|
|
@@ -535,13 +560,11 @@ function maybeReadMore_(stream, state) {
|
|
|
535
560
|
// for virtual (non-string, non-buffer) streams, "length" is somewhat
|
|
536
561
|
// arbitrary, and perhaps not very meaningful.
|
|
537
562
|
Readable.prototype._read = function (n) {
|
|
538
|
-
this
|
|
563
|
+
errorOrDestroy(this, new ERR_METHOD_NOT_IMPLEMENTED('_read()'));
|
|
539
564
|
};
|
|
540
|
-
|
|
541
565
|
Readable.prototype.pipe = function (dest, pipeOpts) {
|
|
542
566
|
var src = this;
|
|
543
567
|
var state = this._readableState;
|
|
544
|
-
|
|
545
568
|
switch (state.pipesCount) {
|
|
546
569
|
case 0:
|
|
547
570
|
state.pipes = dest;
|
|
@@ -555,12 +578,9 @@ Readable.prototype.pipe = function (dest, pipeOpts) {
|
|
|
555
578
|
}
|
|
556
579
|
state.pipesCount += 1;
|
|
557
580
|
debug('pipe count=%d opts=%j', state.pipesCount, pipeOpts);
|
|
558
|
-
|
|
559
581
|
var doEnd = (!pipeOpts || pipeOpts.end !== false) && dest !== process.stdout && dest !== process.stderr;
|
|
560
|
-
|
|
561
582
|
var endFn = doEnd ? onend : unpipe;
|
|
562
|
-
if (state.endEmitted)
|
|
563
|
-
|
|
583
|
+
if (state.endEmitted) process.nextTick(endFn);else src.once('end', endFn);
|
|
564
584
|
dest.on('unpipe', onunpipe);
|
|
565
585
|
function onunpipe(readable, unpipeInfo) {
|
|
566
586
|
debug('onunpipe');
|
|
@@ -571,7 +591,6 @@ Readable.prototype.pipe = function (dest, pipeOpts) {
|
|
|
571
591
|
}
|
|
572
592
|
}
|
|
573
593
|
}
|
|
574
|
-
|
|
575
594
|
function onend() {
|
|
576
595
|
debug('onend');
|
|
577
596
|
dest.end();
|
|
@@ -583,7 +602,6 @@ Readable.prototype.pipe = function (dest, pipeOpts) {
|
|
|
583
602
|
// too slow.
|
|
584
603
|
var ondrain = pipeOnDrain(src);
|
|
585
604
|
dest.on('drain', ondrain);
|
|
586
|
-
|
|
587
605
|
var cleanedUp = false;
|
|
588
606
|
function cleanup() {
|
|
589
607
|
debug('cleanup');
|
|
@@ -596,7 +614,6 @@ Readable.prototype.pipe = function (dest, pipeOpts) {
|
|
|
596
614
|
src.removeListener('end', onend);
|
|
597
615
|
src.removeListener('end', unpipe);
|
|
598
616
|
src.removeListener('data', ondata);
|
|
599
|
-
|
|
600
617
|
cleanedUp = true;
|
|
601
618
|
|
|
602
619
|
// if the reader is waiting for a drain event from this
|
|
@@ -606,26 +623,19 @@ Readable.prototype.pipe = function (dest, pipeOpts) {
|
|
|
606
623
|
// If we don't know, then assume that we are waiting for one.
|
|
607
624
|
if (state.awaitDrain && (!dest._writableState || dest._writableState.needDrain)) ondrain();
|
|
608
625
|
}
|
|
609
|
-
|
|
610
|
-
// If the user pushes more data while we're writing to dest then we'll end up
|
|
611
|
-
// in ondata again. However, we only want to increase awaitDrain once because
|
|
612
|
-
// dest will only emit one 'drain' event for the multiple writes.
|
|
613
|
-
// => Introduce a guard on increasing awaitDrain.
|
|
614
|
-
var increasedAwaitDrain = false;
|
|
615
626
|
src.on('data', ondata);
|
|
616
627
|
function ondata(chunk) {
|
|
617
628
|
debug('ondata');
|
|
618
|
-
increasedAwaitDrain = false;
|
|
619
629
|
var ret = dest.write(chunk);
|
|
620
|
-
|
|
630
|
+
debug('dest.write', ret);
|
|
631
|
+
if (ret === false) {
|
|
621
632
|
// If the user unpiped during `dest.write()`, it is possible
|
|
622
633
|
// to get stuck in a permanently paused state if that write
|
|
623
634
|
// also returned false.
|
|
624
635
|
// => Check whether `dest` is still a piping destination.
|
|
625
636
|
if ((state.pipesCount === 1 && state.pipes === dest || state.pipesCount > 1 && indexOf(state.pipes, dest) !== -1) && !cleanedUp) {
|
|
626
|
-
debug('false write response, pause',
|
|
627
|
-
|
|
628
|
-
increasedAwaitDrain = true;
|
|
637
|
+
debug('false write response, pause', state.awaitDrain);
|
|
638
|
+
state.awaitDrain++;
|
|
629
639
|
}
|
|
630
640
|
src.pause();
|
|
631
641
|
}
|
|
@@ -637,7 +647,7 @@ Readable.prototype.pipe = function (dest, pipeOpts) {
|
|
|
637
647
|
debug('onerror', er);
|
|
638
648
|
unpipe();
|
|
639
649
|
dest.removeListener('error', onerror);
|
|
640
|
-
if (EElistenerCount(dest, 'error') === 0) dest
|
|
650
|
+
if (EElistenerCount(dest, 'error') === 0) errorOrDestroy(dest, er);
|
|
641
651
|
}
|
|
642
652
|
|
|
643
653
|
// Make sure our error handler is attached before userland ones.
|
|
@@ -655,7 +665,6 @@ Readable.prototype.pipe = function (dest, pipeOpts) {
|
|
|
655
665
|
unpipe();
|
|
656
666
|
}
|
|
657
667
|
dest.once('finish', onfinish);
|
|
658
|
-
|
|
659
668
|
function unpipe() {
|
|
660
669
|
debug('unpipe');
|
|
661
670
|
src.unpipe(dest);
|
|
@@ -669,12 +678,10 @@ Readable.prototype.pipe = function (dest, pipeOpts) {
|
|
|
669
678
|
debug('pipe resume');
|
|
670
679
|
src.resume();
|
|
671
680
|
}
|
|
672
|
-
|
|
673
681
|
return dest;
|
|
674
682
|
};
|
|
675
|
-
|
|
676
683
|
function pipeOnDrain(src) {
|
|
677
|
-
return function () {
|
|
684
|
+
return function pipeOnDrainFunctionResult() {
|
|
678
685
|
var state = src._readableState;
|
|
679
686
|
debug('pipeOnDrain', state.awaitDrain);
|
|
680
687
|
if (state.awaitDrain) state.awaitDrain--;
|
|
@@ -684,10 +691,11 @@ function pipeOnDrain(src) {
|
|
|
684
691
|
}
|
|
685
692
|
};
|
|
686
693
|
}
|
|
687
|
-
|
|
688
694
|
Readable.prototype.unpipe = function (dest) {
|
|
689
695
|
var state = this._readableState;
|
|
690
|
-
var unpipeInfo = {
|
|
696
|
+
var unpipeInfo = {
|
|
697
|
+
hasUnpiped: false
|
|
698
|
+
};
|
|
691
699
|
|
|
692
700
|
// if we're not piping anywhere, then do nothing.
|
|
693
701
|
if (state.pipesCount === 0) return this;
|
|
@@ -696,7 +704,6 @@ Readable.prototype.unpipe = function (dest) {
|
|
|
696
704
|
if (state.pipesCount === 1) {
|
|
697
705
|
// passed in one, but it's not the right one.
|
|
698
706
|
if (dest && dest !== state.pipes) return this;
|
|
699
|
-
|
|
700
707
|
if (!dest) dest = state.pipes;
|
|
701
708
|
|
|
702
709
|
// got a match.
|
|
@@ -716,22 +723,19 @@ Readable.prototype.unpipe = function (dest) {
|
|
|
716
723
|
state.pipes = null;
|
|
717
724
|
state.pipesCount = 0;
|
|
718
725
|
state.flowing = false;
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
726
|
+
for (var i = 0; i < len; i++) dests[i].emit('unpipe', this, {
|
|
727
|
+
hasUnpiped: false
|
|
728
|
+
});
|
|
729
|
+
return this;
|
|
723
730
|
}
|
|
724
731
|
|
|
725
732
|
// try to find the right one.
|
|
726
733
|
var index = indexOf(state.pipes, dest);
|
|
727
734
|
if (index === -1) return this;
|
|
728
|
-
|
|
729
735
|
state.pipes.splice(index, 1);
|
|
730
736
|
state.pipesCount -= 1;
|
|
731
737
|
if (state.pipesCount === 1) state.pipes = state.pipes[0];
|
|
732
|
-
|
|
733
738
|
dest.emit('unpipe', this, unpipeInfo);
|
|
734
|
-
|
|
735
739
|
return this;
|
|
736
740
|
};
|
|
737
741
|
|
|
@@ -739,27 +743,69 @@ Readable.prototype.unpipe = function (dest) {
|
|
|
739
743
|
// Ensure readable listeners eventually get something
|
|
740
744
|
Readable.prototype.on = function (ev, fn) {
|
|
741
745
|
var res = Stream.prototype.on.call(this, ev, fn);
|
|
742
|
-
|
|
746
|
+
var state = this._readableState;
|
|
743
747
|
if (ev === 'data') {
|
|
744
|
-
//
|
|
745
|
-
|
|
748
|
+
// update readableListening so that resume() may be a no-op
|
|
749
|
+
// a few lines down. This is needed to support once('readable').
|
|
750
|
+
state.readableListening = this.listenerCount('readable') > 0;
|
|
751
|
+
|
|
752
|
+
// Try start flowing on next tick if stream isn't explicitly paused
|
|
753
|
+
if (state.flowing !== false) this.resume();
|
|
746
754
|
} else if (ev === 'readable') {
|
|
747
|
-
var state = this._readableState;
|
|
748
755
|
if (!state.endEmitted && !state.readableListening) {
|
|
749
756
|
state.readableListening = state.needReadable = true;
|
|
757
|
+
state.flowing = false;
|
|
750
758
|
state.emittedReadable = false;
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
} else if (state.length) {
|
|
759
|
+
debug('on readable', state.length, state.reading);
|
|
760
|
+
if (state.length) {
|
|
754
761
|
emitReadable(this);
|
|
762
|
+
} else if (!state.reading) {
|
|
763
|
+
process.nextTick(nReadingNextTick, this);
|
|
755
764
|
}
|
|
756
765
|
}
|
|
757
766
|
}
|
|
758
|
-
|
|
759
767
|
return res;
|
|
760
768
|
};
|
|
761
769
|
Readable.prototype.addListener = Readable.prototype.on;
|
|
770
|
+
Readable.prototype.removeListener = function (ev, fn) {
|
|
771
|
+
var res = Stream.prototype.removeListener.call(this, ev, fn);
|
|
772
|
+
if (ev === 'readable') {
|
|
773
|
+
// We need to check if there is someone still listening to
|
|
774
|
+
// readable and reset the state. However this needs to happen
|
|
775
|
+
// after readable has been emitted but before I/O (nextTick) to
|
|
776
|
+
// support once('readable', fn) cycles. This means that calling
|
|
777
|
+
// resume within the same tick will have no
|
|
778
|
+
// effect.
|
|
779
|
+
process.nextTick(updateReadableListening, this);
|
|
780
|
+
}
|
|
781
|
+
return res;
|
|
782
|
+
};
|
|
783
|
+
Readable.prototype.removeAllListeners = function (ev) {
|
|
784
|
+
var res = Stream.prototype.removeAllListeners.apply(this, arguments);
|
|
785
|
+
if (ev === 'readable' || ev === undefined) {
|
|
786
|
+
// We need to check if there is someone still listening to
|
|
787
|
+
// readable and reset the state. However this needs to happen
|
|
788
|
+
// after readable has been emitted but before I/O (nextTick) to
|
|
789
|
+
// support once('readable', fn) cycles. This means that calling
|
|
790
|
+
// resume within the same tick will have no
|
|
791
|
+
// effect.
|
|
792
|
+
process.nextTick(updateReadableListening, this);
|
|
793
|
+
}
|
|
794
|
+
return res;
|
|
795
|
+
};
|
|
796
|
+
function updateReadableListening(self) {
|
|
797
|
+
var state = self._readableState;
|
|
798
|
+
state.readableListening = self.listenerCount('readable') > 0;
|
|
799
|
+
if (state.resumeScheduled && !state.paused) {
|
|
800
|
+
// flowing needs to be set to true now, otherwise
|
|
801
|
+
// the upcoming resume will not flow.
|
|
802
|
+
state.flowing = true;
|
|
762
803
|
|
|
804
|
+
// crude way to check if we should resume
|
|
805
|
+
} else if (self.listenerCount('data') > 0) {
|
|
806
|
+
self.resume();
|
|
807
|
+
}
|
|
808
|
+
}
|
|
763
809
|
function nReadingNextTick(self) {
|
|
764
810
|
debug('readable nexttick read 0');
|
|
765
811
|
self.read(0);
|
|
@@ -771,46 +817,45 @@ Readable.prototype.resume = function () {
|
|
|
771
817
|
var state = this._readableState;
|
|
772
818
|
if (!state.flowing) {
|
|
773
819
|
debug('resume');
|
|
774
|
-
|
|
820
|
+
// we flow only if there is no one listening
|
|
821
|
+
// for readable, but we still have to call
|
|
822
|
+
// resume()
|
|
823
|
+
state.flowing = !state.readableListening;
|
|
775
824
|
resume(this, state);
|
|
776
825
|
}
|
|
826
|
+
state.paused = false;
|
|
777
827
|
return this;
|
|
778
828
|
};
|
|
779
|
-
|
|
780
829
|
function resume(stream, state) {
|
|
781
830
|
if (!state.resumeScheduled) {
|
|
782
831
|
state.resumeScheduled = true;
|
|
783
|
-
|
|
832
|
+
process.nextTick(resume_, stream, state);
|
|
784
833
|
}
|
|
785
834
|
}
|
|
786
|
-
|
|
787
835
|
function resume_(stream, state) {
|
|
836
|
+
debug('resume', state.reading);
|
|
788
837
|
if (!state.reading) {
|
|
789
|
-
debug('resume read 0');
|
|
790
838
|
stream.read(0);
|
|
791
839
|
}
|
|
792
|
-
|
|
793
840
|
state.resumeScheduled = false;
|
|
794
|
-
state.awaitDrain = 0;
|
|
795
841
|
stream.emit('resume');
|
|
796
842
|
flow(stream);
|
|
797
843
|
if (state.flowing && !state.reading) stream.read(0);
|
|
798
844
|
}
|
|
799
|
-
|
|
800
845
|
Readable.prototype.pause = function () {
|
|
801
846
|
debug('call pause flowing=%j', this._readableState.flowing);
|
|
802
|
-
if (
|
|
847
|
+
if (this._readableState.flowing !== false) {
|
|
803
848
|
debug('pause');
|
|
804
849
|
this._readableState.flowing = false;
|
|
805
850
|
this.emit('pause');
|
|
806
851
|
}
|
|
852
|
+
this._readableState.paused = true;
|
|
807
853
|
return this;
|
|
808
854
|
};
|
|
809
|
-
|
|
810
855
|
function flow(stream) {
|
|
811
856
|
var state = stream._readableState;
|
|
812
857
|
debug('flow', state.flowing);
|
|
813
|
-
while (state.flowing && stream.read() !== null)
|
|
858
|
+
while (state.flowing && stream.read() !== null);
|
|
814
859
|
}
|
|
815
860
|
|
|
816
861
|
// wrap an old-style stream as the async data source.
|
|
@@ -818,27 +863,22 @@ function flow(stream) {
|
|
|
818
863
|
// It is an ugly unfortunate mess of history.
|
|
819
864
|
Readable.prototype.wrap = function (stream) {
|
|
820
865
|
var _this = this;
|
|
821
|
-
|
|
822
866
|
var state = this._readableState;
|
|
823
867
|
var paused = false;
|
|
824
|
-
|
|
825
868
|
stream.on('end', function () {
|
|
826
869
|
debug('wrapped end');
|
|
827
870
|
if (state.decoder && !state.ended) {
|
|
828
871
|
var chunk = state.decoder.end();
|
|
829
872
|
if (chunk && chunk.length) _this.push(chunk);
|
|
830
873
|
}
|
|
831
|
-
|
|
832
874
|
_this.push(null);
|
|
833
875
|
});
|
|
834
|
-
|
|
835
876
|
stream.on('data', function (chunk) {
|
|
836
877
|
debug('wrapped data');
|
|
837
878
|
if (state.decoder) chunk = state.decoder.write(chunk);
|
|
838
879
|
|
|
839
880
|
// don't skip over falsy values in objectMode
|
|
840
881
|
if (state.objectMode && (chunk === null || chunk === undefined)) return;else if (!state.objectMode && (!chunk || !chunk.length)) return;
|
|
841
|
-
|
|
842
882
|
var ret = _this.push(chunk);
|
|
843
883
|
if (!ret) {
|
|
844
884
|
paused = true;
|
|
@@ -850,8 +890,8 @@ Readable.prototype.wrap = function (stream) {
|
|
|
850
890
|
// important when wrapping filters and duplexes.
|
|
851
891
|
for (var i in stream) {
|
|
852
892
|
if (this[i] === undefined && typeof stream[i] === 'function') {
|
|
853
|
-
this[i] = function (method) {
|
|
854
|
-
return function () {
|
|
893
|
+
this[i] = function methodWrap(method) {
|
|
894
|
+
return function methodWrapReturnFunction() {
|
|
855
895
|
return stream[method].apply(stream, arguments);
|
|
856
896
|
};
|
|
857
897
|
}(i);
|
|
@@ -872,22 +912,60 @@ Readable.prototype.wrap = function (stream) {
|
|
|
872
912
|
stream.resume();
|
|
873
913
|
}
|
|
874
914
|
};
|
|
875
|
-
|
|
876
915
|
return this;
|
|
877
916
|
};
|
|
878
|
-
|
|
917
|
+
if (typeof Symbol === 'function') {
|
|
918
|
+
Readable.prototype[Symbol.asyncIterator] = function () {
|
|
919
|
+
if (createReadableStreamAsyncIterator === undefined) {
|
|
920
|
+
createReadableStreamAsyncIterator = require('./internal/streams/async_iterator');
|
|
921
|
+
}
|
|
922
|
+
return createReadableStreamAsyncIterator(this);
|
|
923
|
+
};
|
|
924
|
+
}
|
|
879
925
|
Object.defineProperty(Readable.prototype, 'readableHighWaterMark', {
|
|
880
926
|
// making it explicit this property is not enumerable
|
|
881
927
|
// because otherwise some prototype manipulation in
|
|
882
928
|
// userland will fail
|
|
883
929
|
enumerable: false,
|
|
884
|
-
get: function () {
|
|
930
|
+
get: function get() {
|
|
885
931
|
return this._readableState.highWaterMark;
|
|
886
932
|
}
|
|
887
933
|
});
|
|
934
|
+
Object.defineProperty(Readable.prototype, 'readableBuffer', {
|
|
935
|
+
// making it explicit this property is not enumerable
|
|
936
|
+
// because otherwise some prototype manipulation in
|
|
937
|
+
// userland will fail
|
|
938
|
+
enumerable: false,
|
|
939
|
+
get: function get() {
|
|
940
|
+
return this._readableState && this._readableState.buffer;
|
|
941
|
+
}
|
|
942
|
+
});
|
|
943
|
+
Object.defineProperty(Readable.prototype, 'readableFlowing', {
|
|
944
|
+
// making it explicit this property is not enumerable
|
|
945
|
+
// because otherwise some prototype manipulation in
|
|
946
|
+
// userland will fail
|
|
947
|
+
enumerable: false,
|
|
948
|
+
get: function get() {
|
|
949
|
+
return this._readableState.flowing;
|
|
950
|
+
},
|
|
951
|
+
set: function set(state) {
|
|
952
|
+
if (this._readableState) {
|
|
953
|
+
this._readableState.flowing = state;
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
});
|
|
888
957
|
|
|
889
958
|
// exposed for testing purposes only.
|
|
890
959
|
Readable._fromList = fromList;
|
|
960
|
+
Object.defineProperty(Readable.prototype, 'readableLength', {
|
|
961
|
+
// making it explicit this property is not enumerable
|
|
962
|
+
// because otherwise some prototype manipulation in
|
|
963
|
+
// userland will fail
|
|
964
|
+
enumerable: false,
|
|
965
|
+
get: function get() {
|
|
966
|
+
return this._readableState.length;
|
|
967
|
+
}
|
|
968
|
+
});
|
|
891
969
|
|
|
892
970
|
// Pluck off n bytes from an array of buffers.
|
|
893
971
|
// Length is the combined lengths of all the buffers in the list.
|
|
@@ -896,121 +974,51 @@ Readable._fromList = fromList;
|
|
|
896
974
|
function fromList(n, state) {
|
|
897
975
|
// nothing buffered
|
|
898
976
|
if (state.length === 0) return null;
|
|
899
|
-
|
|
900
977
|
var ret;
|
|
901
978
|
if (state.objectMode) ret = state.buffer.shift();else if (!n || n >= state.length) {
|
|
902
979
|
// read it all, truncate the list
|
|
903
|
-
if (state.decoder) ret = state.buffer.join('');else if (state.buffer.length === 1) ret = state.buffer.
|
|
980
|
+
if (state.decoder) ret = state.buffer.join('');else if (state.buffer.length === 1) ret = state.buffer.first();else ret = state.buffer.concat(state.length);
|
|
904
981
|
state.buffer.clear();
|
|
905
982
|
} else {
|
|
906
983
|
// read part of list
|
|
907
|
-
ret =
|
|
984
|
+
ret = state.buffer.consume(n, state.decoder);
|
|
908
985
|
}
|
|
909
|
-
|
|
910
986
|
return ret;
|
|
911
987
|
}
|
|
912
|
-
|
|
913
|
-
// Extracts only enough buffered data to satisfy the amount requested.
|
|
914
|
-
// This function is designed to be inlinable, so please take care when making
|
|
915
|
-
// changes to the function body.
|
|
916
|
-
function fromListPartial(n, list, hasStrings) {
|
|
917
|
-
var ret;
|
|
918
|
-
if (n < list.head.data.length) {
|
|
919
|
-
// slice is the same for buffers and strings
|
|
920
|
-
ret = list.head.data.slice(0, n);
|
|
921
|
-
list.head.data = list.head.data.slice(n);
|
|
922
|
-
} else if (n === list.head.data.length) {
|
|
923
|
-
// first chunk is a perfect match
|
|
924
|
-
ret = list.shift();
|
|
925
|
-
} else {
|
|
926
|
-
// result spans more than one buffer
|
|
927
|
-
ret = hasStrings ? copyFromBufferString(n, list) : copyFromBuffer(n, list);
|
|
928
|
-
}
|
|
929
|
-
return ret;
|
|
930
|
-
}
|
|
931
|
-
|
|
932
|
-
// Copies a specified amount of characters from the list of buffered data
|
|
933
|
-
// chunks.
|
|
934
|
-
// This function is designed to be inlinable, so please take care when making
|
|
935
|
-
// changes to the function body.
|
|
936
|
-
function copyFromBufferString(n, list) {
|
|
937
|
-
var p = list.head;
|
|
938
|
-
var c = 1;
|
|
939
|
-
var ret = p.data;
|
|
940
|
-
n -= ret.length;
|
|
941
|
-
while (p = p.next) {
|
|
942
|
-
var str = p.data;
|
|
943
|
-
var nb = n > str.length ? str.length : n;
|
|
944
|
-
if (nb === str.length) ret += str;else ret += str.slice(0, n);
|
|
945
|
-
n -= nb;
|
|
946
|
-
if (n === 0) {
|
|
947
|
-
if (nb === str.length) {
|
|
948
|
-
++c;
|
|
949
|
-
if (p.next) list.head = p.next;else list.head = list.tail = null;
|
|
950
|
-
} else {
|
|
951
|
-
list.head = p;
|
|
952
|
-
p.data = str.slice(nb);
|
|
953
|
-
}
|
|
954
|
-
break;
|
|
955
|
-
}
|
|
956
|
-
++c;
|
|
957
|
-
}
|
|
958
|
-
list.length -= c;
|
|
959
|
-
return ret;
|
|
960
|
-
}
|
|
961
|
-
|
|
962
|
-
// Copies a specified amount of bytes from the list of buffered data chunks.
|
|
963
|
-
// This function is designed to be inlinable, so please take care when making
|
|
964
|
-
// changes to the function body.
|
|
965
|
-
function copyFromBuffer(n, list) {
|
|
966
|
-
var ret = Buffer.allocUnsafe(n);
|
|
967
|
-
var p = list.head;
|
|
968
|
-
var c = 1;
|
|
969
|
-
p.data.copy(ret);
|
|
970
|
-
n -= p.data.length;
|
|
971
|
-
while (p = p.next) {
|
|
972
|
-
var buf = p.data;
|
|
973
|
-
var nb = n > buf.length ? buf.length : n;
|
|
974
|
-
buf.copy(ret, ret.length - n, 0, nb);
|
|
975
|
-
n -= nb;
|
|
976
|
-
if (n === 0) {
|
|
977
|
-
if (nb === buf.length) {
|
|
978
|
-
++c;
|
|
979
|
-
if (p.next) list.head = p.next;else list.head = list.tail = null;
|
|
980
|
-
} else {
|
|
981
|
-
list.head = p;
|
|
982
|
-
p.data = buf.slice(nb);
|
|
983
|
-
}
|
|
984
|
-
break;
|
|
985
|
-
}
|
|
986
|
-
++c;
|
|
987
|
-
}
|
|
988
|
-
list.length -= c;
|
|
989
|
-
return ret;
|
|
990
|
-
}
|
|
991
|
-
|
|
992
988
|
function endReadable(stream) {
|
|
993
989
|
var state = stream._readableState;
|
|
994
|
-
|
|
995
|
-
// If we get here before consuming all the bytes, then that is a
|
|
996
|
-
// bug in node. Should never happen.
|
|
997
|
-
if (state.length > 0) throw new Error('"endReadable()" called on non-empty stream');
|
|
998
|
-
|
|
990
|
+
debug('endReadable', state.endEmitted);
|
|
999
991
|
if (!state.endEmitted) {
|
|
1000
992
|
state.ended = true;
|
|
1001
|
-
|
|
993
|
+
process.nextTick(endReadableNT, state, stream);
|
|
1002
994
|
}
|
|
1003
995
|
}
|
|
1004
|
-
|
|
1005
996
|
function endReadableNT(state, stream) {
|
|
997
|
+
debug('endReadableNT', state.endEmitted, state.length);
|
|
998
|
+
|
|
1006
999
|
// Check that we didn't get one last unshift.
|
|
1007
1000
|
if (!state.endEmitted && state.length === 0) {
|
|
1008
1001
|
state.endEmitted = true;
|
|
1009
1002
|
stream.readable = false;
|
|
1010
1003
|
stream.emit('end');
|
|
1004
|
+
if (state.autoDestroy) {
|
|
1005
|
+
// In case of duplex streams we need a way to detect
|
|
1006
|
+
// if the writable side is ready for autoDestroy as well
|
|
1007
|
+
var wState = stream._writableState;
|
|
1008
|
+
if (!wState || wState.autoDestroy && wState.finished) {
|
|
1009
|
+
stream.destroy();
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1011
1012
|
}
|
|
1012
1013
|
}
|
|
1013
|
-
|
|
1014
|
+
if (typeof Symbol === 'function') {
|
|
1015
|
+
Readable.from = function (iterable, opts) {
|
|
1016
|
+
if (from === undefined) {
|
|
1017
|
+
from = require('./internal/streams/from');
|
|
1018
|
+
}
|
|
1019
|
+
return from(Readable, iterable, opts);
|
|
1020
|
+
};
|
|
1021
|
+
}
|
|
1014
1022
|
function indexOf(xs, x) {
|
|
1015
1023
|
for (var i = 0, l = xs.length; i < l; i++) {
|
|
1016
1024
|
if (xs[i] === x) return i;
|