Leon4gr45 commited on
Commit
09bc8fe
·
verified ·
1 Parent(s): 5c0a36d

Upload folder using huggingface_hub (part 4)

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. node_modules/statuses/index.js +146 -0
  2. node_modules/statuses/package.json +49 -0
  3. node_modules/stream-browserify/.airtap.yml +20 -0
  4. node_modules/stream-browserify/.github/FUNDING.yml +12 -0
  5. node_modules/stream-browserify/.travis.yml +24 -0
  6. node_modules/stream-browserify/CHANGELOG.md +8 -0
  7. node_modules/stream-browserify/LICENSE +20 -0
  8. node_modules/stream-browserify/index.js +129 -0
  9. node_modules/stream-browserify/node_modules/readable-stream/CONTRIBUTING.md +38 -0
  10. node_modules/stream-browserify/node_modules/readable-stream/GOVERNANCE.md +136 -0
  11. node_modules/stream-browserify/node_modules/readable-stream/LICENSE +47 -0
  12. node_modules/stream-browserify/node_modules/readable-stream/README.md +106 -0
  13. node_modules/stream-browserify/node_modules/readable-stream/errors-browser.js +127 -0
  14. node_modules/stream-browserify/node_modules/readable-stream/errors.js +116 -0
  15. node_modules/stream-browserify/node_modules/readable-stream/experimentalWarning.js +17 -0
  16. node_modules/stream-browserify/node_modules/readable-stream/lib/_stream_duplex.js +126 -0
  17. node_modules/stream-browserify/node_modules/readable-stream/lib/_stream_passthrough.js +37 -0
  18. node_modules/stream-browserify/node_modules/readable-stream/lib/_stream_readable.js +1027 -0
  19. node_modules/stream-browserify/node_modules/readable-stream/lib/_stream_transform.js +190 -0
  20. node_modules/stream-browserify/node_modules/readable-stream/lib/_stream_writable.js +641 -0
  21. node_modules/stream-browserify/node_modules/readable-stream/lib/internal/streams/async_iterator.js +180 -0
  22. node_modules/stream-browserify/node_modules/readable-stream/lib/internal/streams/buffer_list.js +183 -0
  23. node_modules/stream-browserify/node_modules/readable-stream/lib/internal/streams/destroy.js +96 -0
  24. node_modules/stream-browserify/node_modules/readable-stream/lib/internal/streams/end-of-stream.js +86 -0
  25. node_modules/stream-browserify/node_modules/readable-stream/lib/internal/streams/from-browser.js +3 -0
  26. node_modules/stream-browserify/node_modules/readable-stream/lib/internal/streams/from.js +52 -0
  27. node_modules/stream-browserify/node_modules/readable-stream/lib/internal/streams/pipeline.js +86 -0
  28. node_modules/stream-browserify/node_modules/readable-stream/lib/internal/streams/state.js +22 -0
  29. node_modules/stream-browserify/node_modules/readable-stream/lib/internal/streams/stream-browser.js +1 -0
  30. node_modules/stream-browserify/node_modules/readable-stream/lib/internal/streams/stream.js +1 -0
  31. node_modules/stream-browserify/node_modules/readable-stream/package.json +68 -0
  32. node_modules/stream-browserify/node_modules/readable-stream/readable-browser.js +9 -0
  33. node_modules/stream-browserify/node_modules/readable-stream/readable.js +16 -0
  34. node_modules/stream-browserify/package.json +54 -0
  35. node_modules/stream-browserify/readme.markdown +32 -0
  36. node_modules/stream-browserify/security.md +10 -0
  37. node_modules/stream-browserify/test/buf.js +33 -0
  38. node_modules/stream-browserify/test/index.js +2 -0
  39. node_modules/stream-browserify/test/pipeline.js +38 -0
  40. node_modules/stream-browserify/test/use-stream.js +4 -0
  41. node_modules/stream-http/LICENSE +24 -0
  42. node_modules/stream-http/README.md +134 -0
  43. node_modules/stream-http/index.js +85 -0
  44. node_modules/stream-http/lib/capability.js +59 -0
  45. node_modules/stream-http/lib/request.js +352 -0
  46. node_modules/stream-http/lib/response.js +211 -0
  47. node_modules/stream-http/node_modules/readable-stream/CONTRIBUTING.md +38 -0
  48. node_modules/stream-http/node_modules/readable-stream/GOVERNANCE.md +136 -0
  49. node_modules/stream-http/node_modules/readable-stream/LICENSE +47 -0
  50. node_modules/stream-http/node_modules/readable-stream/README.md +106 -0
node_modules/statuses/index.js ADDED
@@ -0,0 +1,146 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*!
2
+ * statuses
3
+ * Copyright(c) 2014 Jonathan Ong
4
+ * Copyright(c) 2016 Douglas Christopher Wilson
5
+ * MIT Licensed
6
+ */
7
+
8
+ 'use strict'
9
+
10
+ /**
11
+ * Module dependencies.
12
+ * @private
13
+ */
14
+
15
+ var codes = require('./codes.json')
16
+
17
+ /**
18
+ * Module exports.
19
+ * @public
20
+ */
21
+
22
+ module.exports = status
23
+
24
+ // status code to message map
25
+ status.message = codes
26
+
27
+ // status message (lower-case) to code map
28
+ status.code = createMessageToStatusCodeMap(codes)
29
+
30
+ // array of status codes
31
+ status.codes = createStatusCodeList(codes)
32
+
33
+ // status codes for redirects
34
+ status.redirect = {
35
+ 300: true,
36
+ 301: true,
37
+ 302: true,
38
+ 303: true,
39
+ 305: true,
40
+ 307: true,
41
+ 308: true
42
+ }
43
+
44
+ // status codes for empty bodies
45
+ status.empty = {
46
+ 204: true,
47
+ 205: true,
48
+ 304: true
49
+ }
50
+
51
+ // status codes for when you should retry the request
52
+ status.retry = {
53
+ 502: true,
54
+ 503: true,
55
+ 504: true
56
+ }
57
+
58
+ /**
59
+ * Create a map of message to status code.
60
+ * @private
61
+ */
62
+
63
+ function createMessageToStatusCodeMap (codes) {
64
+ var map = {}
65
+
66
+ Object.keys(codes).forEach(function forEachCode (code) {
67
+ var message = codes[code]
68
+ var status = Number(code)
69
+
70
+ // populate map
71
+ map[message.toLowerCase()] = status
72
+ })
73
+
74
+ return map
75
+ }
76
+
77
+ /**
78
+ * Create a list of all status codes.
79
+ * @private
80
+ */
81
+
82
+ function createStatusCodeList (codes) {
83
+ return Object.keys(codes).map(function mapCode (code) {
84
+ return Number(code)
85
+ })
86
+ }
87
+
88
+ /**
89
+ * Get the status code for given message.
90
+ * @private
91
+ */
92
+
93
+ function getStatusCode (message) {
94
+ var msg = message.toLowerCase()
95
+
96
+ if (!Object.prototype.hasOwnProperty.call(status.code, msg)) {
97
+ throw new Error('invalid status message: "' + message + '"')
98
+ }
99
+
100
+ return status.code[msg]
101
+ }
102
+
103
+ /**
104
+ * Get the status message for given code.
105
+ * @private
106
+ */
107
+
108
+ function getStatusMessage (code) {
109
+ if (!Object.prototype.hasOwnProperty.call(status.message, code)) {
110
+ throw new Error('invalid status code: ' + code)
111
+ }
112
+
113
+ return status.message[code]
114
+ }
115
+
116
+ /**
117
+ * Get the status code.
118
+ *
119
+ * Given a number, this will throw if it is not a known status
120
+ * code, otherwise the code will be returned. Given a string,
121
+ * the string will be parsed for a number and return the code
122
+ * if valid, otherwise will lookup the code assuming this is
123
+ * the status message.
124
+ *
125
+ * @param {string|number} code
126
+ * @returns {number}
127
+ * @public
128
+ */
129
+
130
+ function status (code) {
131
+ if (typeof code === 'number') {
132
+ return getStatusMessage(code)
133
+ }
134
+
135
+ if (typeof code !== 'string') {
136
+ throw new TypeError('code must be a number or string')
137
+ }
138
+
139
+ // '403'
140
+ var n = parseInt(code, 10)
141
+ if (!isNaN(n)) {
142
+ return getStatusMessage(n)
143
+ }
144
+
145
+ return getStatusCode(code)
146
+ }
node_modules/statuses/package.json ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "statuses",
3
+ "description": "HTTP status utility",
4
+ "version": "2.0.2",
5
+ "contributors": [
6
+ "Douglas Christopher Wilson <doug@somethingdoug.com>",
7
+ "Jonathan Ong <me@jongleberry.com> (http://jongleberry.com)"
8
+ ],
9
+ "repository": "jshttp/statuses",
10
+ "license": "MIT",
11
+ "keywords": [
12
+ "http",
13
+ "status",
14
+ "code"
15
+ ],
16
+ "files": [
17
+ "HISTORY.md",
18
+ "index.js",
19
+ "codes.json",
20
+ "LICENSE"
21
+ ],
22
+ "devDependencies": {
23
+ "csv-parse": "4.16.3",
24
+ "eslint": "7.19.0",
25
+ "eslint-config-standard": "14.1.1",
26
+ "eslint-plugin-import": "2.31.0",
27
+ "eslint-plugin-markdown": "1.0.2",
28
+ "eslint-plugin-node": "11.1.0",
29
+ "eslint-plugin-promise": "4.3.1",
30
+ "eslint-plugin-standard": "4.1.0",
31
+ "mocha": "8.4.0",
32
+ "nyc": "15.1.0",
33
+ "raw-body": "2.5.2",
34
+ "stream-to-array": "2.3.0"
35
+ },
36
+ "engines": {
37
+ "node": ">= 0.8"
38
+ },
39
+ "scripts": {
40
+ "build": "node scripts/build.js",
41
+ "fetch": "node scripts/fetch-apache.js && node scripts/fetch-iana.js && node scripts/fetch-nginx.js && node scripts/fetch-node.js",
42
+ "lint": "eslint --plugin markdown --ext js,md .",
43
+ "test": "mocha --reporter spec --check-leaks --bail test/",
44
+ "test-ci": "nyc --reporter=lcov --reporter=text npm test",
45
+ "test-cov": "nyc --reporter=html --reporter=text npm test",
46
+ "update": "npm run fetch && npm run build",
47
+ "version": "node scripts/version-history.js && git add HISTORY.md"
48
+ }
49
+ }
node_modules/stream-browserify/.airtap.yml ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ sauce_connect: true
2
+ loopback: airtap.local
3
+ browsers:
4
+ - name: chrome
5
+ version: latest
6
+ - name: firefox
7
+ # extended support releases 52, 60, 68
8
+ version: [52, 60, 68, latest]
9
+ - name: safari
10
+ version: 9..latest
11
+ - name: iphone
12
+ version: latest
13
+ - name: ie
14
+ version: 9..latest
15
+ - name: microsoftedge
16
+ version: 13..latest
17
+ browserify:
18
+ - plugin: ./test/use-stream.js
19
+ - require: tape
20
+ expose: tape
node_modules/stream-browserify/.github/FUNDING.yml ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # These are supported funding model platforms
2
+
3
+ github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4
+ patreon: # Replace with a single Patreon username
5
+ open_collective: # Replace with a single Open Collective username
6
+ ko_fi: # Replace with a single Ko-fi username
7
+ tidelift: npm/stream-browserify
8
+ community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9
+ liberapay: # Replace with a single Liberapay username
10
+ issuehunt: # Replace with a single IssueHunt username
11
+ otechie: # Replace with a single Otechie username
12
+ custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
node_modules/stream-browserify/.travis.yml ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ os: linux
2
+ dist: bionic
3
+ language: node_js
4
+ jobs:
5
+ include:
6
+ - name: Run browser tests with airtap
7
+ node_js: stable
8
+ script: npm run test:browsers
9
+ addons:
10
+ sauce_connect: true
11
+ hosts:
12
+ - airtap.local
13
+ - name: Test on stable Node.js
14
+ node_js: stable
15
+ - name: Test on Node.js 12.x
16
+ node_js: 12
17
+ - name: Test on Node.js 10.x
18
+ node_js: 10
19
+ - name: Test on Node.js 8.x
20
+ node_js: 8
21
+ - name: Test on Node.js 6.x
22
+ node_js: 6
23
+ - name: Test on Node.js 4.x
24
+ node_js: 4
node_modules/stream-browserify/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ # stream-browserify change log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ This project adheres to [Semantic Versioning](http://semver.org/).
6
+
7
+ ## 3.0.0
8
+ * Upgrade to `readable-stream` 3. For breaking changes, see the [readable-stream notes](https://github.com/nodejs/readable-stream#version-3xx).
node_modules/stream-browserify/LICENSE ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) James Halliday
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
node_modules/stream-browserify/index.js ADDED
@@ -0,0 +1,129 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright Joyent, Inc. and other Node contributors.
2
+ //
3
+ // Permission is hereby granted, free of charge, to any person obtaining a
4
+ // copy of this software and associated documentation files (the
5
+ // "Software"), to deal in the Software without restriction, including
6
+ // without limitation the rights to use, copy, modify, merge, publish,
7
+ // distribute, sublicense, and/or sell copies of the Software, and to permit
8
+ // persons to whom the Software is furnished to do so, subject to the
9
+ // following conditions:
10
+ //
11
+ // The above copyright notice and this permission notice shall be included
12
+ // in all copies or substantial portions of the Software.
13
+ //
14
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15
+ // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17
+ // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18
+ // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19
+ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20
+ // USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ module.exports = Stream;
23
+
24
+ var EE = require('events').EventEmitter;
25
+ var inherits = require('inherits');
26
+
27
+ inherits(Stream, EE);
28
+ Stream.Readable = require('readable-stream/lib/_stream_readable.js');
29
+ Stream.Writable = require('readable-stream/lib/_stream_writable.js');
30
+ Stream.Duplex = require('readable-stream/lib/_stream_duplex.js');
31
+ Stream.Transform = require('readable-stream/lib/_stream_transform.js');
32
+ Stream.PassThrough = require('readable-stream/lib/_stream_passthrough.js');
33
+ Stream.finished = require('readable-stream/lib/internal/streams/end-of-stream.js')
34
+ Stream.pipeline = require('readable-stream/lib/internal/streams/pipeline.js')
35
+
36
+ // Backwards-compat with node 0.4.x
37
+ Stream.Stream = Stream;
38
+
39
+
40
+
41
+ // old-style streams. Note that the pipe method (the only relevant
42
+ // part of this class) is overridden in the Readable class.
43
+
44
+ function Stream() {
45
+ EE.call(this);
46
+ }
47
+
48
+ Stream.prototype.pipe = function(dest, options) {
49
+ var source = this;
50
+
51
+ function ondata(chunk) {
52
+ if (dest.writable) {
53
+ if (false === dest.write(chunk) && source.pause) {
54
+ source.pause();
55
+ }
56
+ }
57
+ }
58
+
59
+ source.on('data', ondata);
60
+
61
+ function ondrain() {
62
+ if (source.readable && source.resume) {
63
+ source.resume();
64
+ }
65
+ }
66
+
67
+ dest.on('drain', ondrain);
68
+
69
+ // If the 'end' option is not supplied, dest.end() will be called when
70
+ // source gets the 'end' or 'close' events. Only dest.end() once.
71
+ if (!dest._isStdio && (!options || options.end !== false)) {
72
+ source.on('end', onend);
73
+ source.on('close', onclose);
74
+ }
75
+
76
+ var didOnEnd = false;
77
+ function onend() {
78
+ if (didOnEnd) return;
79
+ didOnEnd = true;
80
+
81
+ dest.end();
82
+ }
83
+
84
+
85
+ function onclose() {
86
+ if (didOnEnd) return;
87
+ didOnEnd = true;
88
+
89
+ if (typeof dest.destroy === 'function') dest.destroy();
90
+ }
91
+
92
+ // don't leave dangling pipes when there are errors.
93
+ function onerror(er) {
94
+ cleanup();
95
+ if (EE.listenerCount(this, 'error') === 0) {
96
+ throw er; // Unhandled stream error in pipe.
97
+ }
98
+ }
99
+
100
+ source.on('error', onerror);
101
+ dest.on('error', onerror);
102
+
103
+ // remove all the event listeners that were added.
104
+ function cleanup() {
105
+ source.removeListener('data', ondata);
106
+ dest.removeListener('drain', ondrain);
107
+
108
+ source.removeListener('end', onend);
109
+ source.removeListener('close', onclose);
110
+
111
+ source.removeListener('error', onerror);
112
+ dest.removeListener('error', onerror);
113
+
114
+ source.removeListener('end', cleanup);
115
+ source.removeListener('close', cleanup);
116
+
117
+ dest.removeListener('close', cleanup);
118
+ }
119
+
120
+ source.on('end', cleanup);
121
+ source.on('close', cleanup);
122
+
123
+ dest.on('close', cleanup);
124
+
125
+ dest.emit('pipe', source);
126
+
127
+ // Allow for unix-like usage: A.pipe(B).pipe(C)
128
+ return dest;
129
+ };
node_modules/stream-browserify/node_modules/readable-stream/CONTRIBUTING.md ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Developer's Certificate of Origin 1.1
2
+
3
+ By making a contribution to this project, I certify that:
4
+
5
+ * (a) The contribution was created in whole or in part by me and I
6
+ have the right to submit it under the open source license
7
+ indicated in the file; or
8
+
9
+ * (b) The contribution is based upon previous work that, to the best
10
+ of my knowledge, is covered under an appropriate open source
11
+ license and I have the right under that license to submit that
12
+ work with modifications, whether created in whole or in part
13
+ by me, under the same open source license (unless I am
14
+ permitted to submit under a different license), as indicated
15
+ in the file; or
16
+
17
+ * (c) The contribution was provided directly to me by some other
18
+ person who certified (a), (b) or (c) and I have not modified
19
+ it.
20
+
21
+ * (d) I understand and agree that this project and the contribution
22
+ are public and that a record of the contribution (including all
23
+ personal information I submit with it, including my sign-off) is
24
+ maintained indefinitely and may be redistributed consistent with
25
+ this project or the open source license(s) involved.
26
+
27
+ ## Moderation Policy
28
+
29
+ The [Node.js Moderation Policy] applies to this WG.
30
+
31
+ ## Code of Conduct
32
+
33
+ The [Node.js Code of Conduct][] applies to this WG.
34
+
35
+ [Node.js Code of Conduct]:
36
+ https://github.com/nodejs/node/blob/master/CODE_OF_CONDUCT.md
37
+ [Node.js Moderation Policy]:
38
+ https://github.com/nodejs/TSC/blob/master/Moderation-Policy.md
node_modules/stream-browserify/node_modules/readable-stream/GOVERNANCE.md ADDED
@@ -0,0 +1,136 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Streams Working Group
2
+
3
+ The Node.js Streams is jointly governed by a Working Group
4
+ (WG)
5
+ that is responsible for high-level guidance of the project.
6
+
7
+ The WG has final authority over this project including:
8
+
9
+ * Technical direction
10
+ * Project governance and process (including this policy)
11
+ * Contribution policy
12
+ * GitHub repository hosting
13
+ * Conduct guidelines
14
+ * Maintaining the list of additional Collaborators
15
+
16
+ For the current list of WG members, see the project
17
+ [README.md](./README.md#current-project-team-members).
18
+
19
+ ### Collaborators
20
+
21
+ The readable-stream GitHub repository is
22
+ maintained by the WG and additional Collaborators who are added by the
23
+ WG on an ongoing basis.
24
+
25
+ Individuals making significant and valuable contributions are made
26
+ Collaborators and given commit-access to the project. These
27
+ individuals are identified by the WG and their addition as
28
+ Collaborators is discussed during the WG meeting.
29
+
30
+ _Note:_ If you make a significant contribution and are not considered
31
+ for commit-access log an issue or contact a WG member directly and it
32
+ will be brought up in the next WG meeting.
33
+
34
+ Modifications of the contents of the readable-stream repository are
35
+ made on
36
+ a collaborative basis. Anybody with a GitHub account may propose a
37
+ modification via pull request and it will be considered by the project
38
+ Collaborators. All pull requests must be reviewed and accepted by a
39
+ Collaborator with sufficient expertise who is able to take full
40
+ responsibility for the change. In the case of pull requests proposed
41
+ by an existing Collaborator, an additional Collaborator is required
42
+ for sign-off. Consensus should be sought if additional Collaborators
43
+ participate and there is disagreement around a particular
44
+ modification. See _Consensus Seeking Process_ below for further detail
45
+ on the consensus model used for governance.
46
+
47
+ Collaborators may opt to elevate significant or controversial
48
+ modifications, or modifications that have not found consensus to the
49
+ WG for discussion by assigning the ***WG-agenda*** tag to a pull
50
+ request or issue. The WG should serve as the final arbiter where
51
+ required.
52
+
53
+ For the current list of Collaborators, see the project
54
+ [README.md](./README.md#members).
55
+
56
+ ### WG Membership
57
+
58
+ WG seats are not time-limited. There is no fixed size of the WG.
59
+ However, the expected target is between 6 and 12, to ensure adequate
60
+ coverage of important areas of expertise, balanced with the ability to
61
+ make decisions efficiently.
62
+
63
+ There is no specific set of requirements or qualifications for WG
64
+ membership beyond these rules.
65
+
66
+ The WG may add additional members to the WG by unanimous consensus.
67
+
68
+ A WG member may be removed from the WG by voluntary resignation, or by
69
+ unanimous consensus of all other WG members.
70
+
71
+ Changes to WG membership should be posted in the agenda, and may be
72
+ suggested as any other agenda item (see "WG Meetings" below).
73
+
74
+ If an addition or removal is proposed during a meeting, and the full
75
+ WG is not in attendance to participate, then the addition or removal
76
+ is added to the agenda for the subsequent meeting. This is to ensure
77
+ that all members are given the opportunity to participate in all
78
+ membership decisions. If a WG member is unable to attend a meeting
79
+ where a planned membership decision is being made, then their consent
80
+ is assumed.
81
+
82
+ No more than 1/3 of the WG members may be affiliated with the same
83
+ employer. If removal or resignation of a WG member, or a change of
84
+ employment by a WG member, creates a situation where more than 1/3 of
85
+ the WG membership shares an employer, then the situation must be
86
+ immediately remedied by the resignation or removal of one or more WG
87
+ members affiliated with the over-represented employer(s).
88
+
89
+ ### WG Meetings
90
+
91
+ The WG meets occasionally on a Google Hangout On Air. A designated moderator
92
+ approved by the WG runs the meeting. Each meeting should be
93
+ published to YouTube.
94
+
95
+ Items are added to the WG agenda that are considered contentious or
96
+ are modifications of governance, contribution policy, WG membership,
97
+ or release process.
98
+
99
+ The intention of the agenda is not to approve or review all patches;
100
+ that should happen continuously on GitHub and be handled by the larger
101
+ group of Collaborators.
102
+
103
+ Any community member or contributor can ask that something be added to
104
+ the next meeting's agenda by logging a GitHub Issue. Any Collaborator,
105
+ WG member or the moderator can add the item to the agenda by adding
106
+ the ***WG-agenda*** tag to the issue.
107
+
108
+ Prior to each WG meeting the moderator will share the Agenda with
109
+ members of the WG. WG members can add any items they like to the
110
+ agenda at the beginning of each meeting. The moderator and the WG
111
+ cannot veto or remove items.
112
+
113
+ The WG may invite persons or representatives from certain projects to
114
+ participate in a non-voting capacity.
115
+
116
+ The moderator is responsible for summarizing the discussion of each
117
+ agenda item and sends it as a pull request after the meeting.
118
+
119
+ ### Consensus Seeking Process
120
+
121
+ The WG follows a
122
+ [Consensus
123
+ Seeking](http://en.wikipedia.org/wiki/Consensus-seeking_decision-making)
124
+ decision-making model.
125
+
126
+ When an agenda item has appeared to reach a consensus the moderator
127
+ will ask "Does anyone object?" as a final call for dissent from the
128
+ consensus.
129
+
130
+ If an agenda item cannot reach a consensus a WG member can call for
131
+ either a closing vote or a vote to table the issue to the next
132
+ meeting. The call for a vote must be seconded by a majority of the WG
133
+ or else the discussion will continue. Simple majority wins.
134
+
135
+ Note that changes to WG membership require a majority consensus. See
136
+ "WG Membership" above.
node_modules/stream-browserify/node_modules/readable-stream/LICENSE ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Node.js is licensed for use as follows:
2
+
3
+ """
4
+ Copyright Node.js contributors. All rights reserved.
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to
8
+ deal in the Software without restriction, including without limitation the
9
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10
+ sell copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in
14
+ all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22
+ IN THE SOFTWARE.
23
+ """
24
+
25
+ This license applies to parts of Node.js originating from the
26
+ https://github.com/joyent/node repository:
27
+
28
+ """
29
+ Copyright Joyent, Inc. and other Node contributors. All rights reserved.
30
+ Permission is hereby granted, free of charge, to any person obtaining a copy
31
+ of this software and associated documentation files (the "Software"), to
32
+ deal in the Software without restriction, including without limitation the
33
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
34
+ sell copies of the Software, and to permit persons to whom the Software is
35
+ furnished to do so, subject to the following conditions:
36
+
37
+ The above copyright notice and this permission notice shall be included in
38
+ all copies or substantial portions of the Software.
39
+
40
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
41
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
42
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
43
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
44
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
45
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
46
+ IN THE SOFTWARE.
47
+ """
node_modules/stream-browserify/node_modules/readable-stream/README.md ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # readable-stream
2
+
3
+ ***Node.js core streams for userland*** [![Build Status](https://travis-ci.com/nodejs/readable-stream.svg?branch=master)](https://travis-ci.com/nodejs/readable-stream)
4
+
5
+
6
+ [![NPM](https://nodei.co/npm/readable-stream.png?downloads=true&downloadRank=true)](https://nodei.co/npm/readable-stream/)
7
+ [![NPM](https://nodei.co/npm-dl/readable-stream.png?&months=6&height=3)](https://nodei.co/npm/readable-stream/)
8
+
9
+
10
+ [![Sauce Test Status](https://saucelabs.com/browser-matrix/readabe-stream.svg)](https://saucelabs.com/u/readabe-stream)
11
+
12
+ ```bash
13
+ npm install --save readable-stream
14
+ ```
15
+
16
+ This package is a mirror of the streams implementations in Node.js.
17
+
18
+ Full documentation may be found on the [Node.js website](https://nodejs.org/dist/v10.18.1/docs/api/stream.html).
19
+
20
+ If you want to guarantee a stable streams base, regardless of what version of
21
+ 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).
22
+
23
+ As of version 2.0.0 **readable-stream** uses semantic versioning.
24
+
25
+ ## Version 3.x.x
26
+
27
+ v3.x.x of `readable-stream` is a cut from Node 10. This version supports Node 6, 8, and 10, as well as evergreen browsers, IE 11 and latest Safari. The breaking changes introduced by v3 are composed by the combined breaking changes in [Node v9](https://nodejs.org/en/blog/release/v9.0.0/) and [Node v10](https://nodejs.org/en/blog/release/v10.0.0/), as follows:
28
+
29
+ 1. Error codes: https://github.com/nodejs/node/pull/13310,
30
+ https://github.com/nodejs/node/pull/13291,
31
+ https://github.com/nodejs/node/pull/16589,
32
+ https://github.com/nodejs/node/pull/15042,
33
+ https://github.com/nodejs/node/pull/15665,
34
+ https://github.com/nodejs/readable-stream/pull/344
35
+ 2. 'readable' have precedence over flowing
36
+ https://github.com/nodejs/node/pull/18994
37
+ 3. make virtual methods errors consistent
38
+ https://github.com/nodejs/node/pull/18813
39
+ 4. updated streams error handling
40
+ https://github.com/nodejs/node/pull/18438
41
+ 5. writable.end should return this.
42
+ https://github.com/nodejs/node/pull/18780
43
+ 6. readable continues to read when push('')
44
+ https://github.com/nodejs/node/pull/18211
45
+ 7. add custom inspect to BufferList
46
+ https://github.com/nodejs/node/pull/17907
47
+ 8. always defer 'readable' with nextTick
48
+ https://github.com/nodejs/node/pull/17979
49
+
50
+ ## Version 2.x.x
51
+ v2.x.x of `readable-stream` is a cut of the stream module from Node 8 (there have been no semver-major changes from Node 4 to 8). This version supports all Node.js versions from 0.8, as well as evergreen browsers and IE 10 & 11.
52
+
53
+ ### Big Thanks
54
+
55
+ Cross-browser Testing Platform and Open Source <3 Provided by [Sauce Labs][sauce]
56
+
57
+ # Usage
58
+
59
+ You can swap your `require('stream')` with `require('readable-stream')`
60
+ without any changes, if you are just using one of the main classes and
61
+ functions.
62
+
63
+ ```js
64
+ const {
65
+ Readable,
66
+ Writable,
67
+ Transform,
68
+ Duplex,
69
+ pipeline,
70
+ finished
71
+ } = require('readable-stream')
72
+ ````
73
+
74
+ Note that `require('stream')` will return `Stream`, while
75
+ `require('readable-stream')` will return `Readable`. We discourage using
76
+ whatever is exported directly, but rather use one of the properties as
77
+ shown in the example above.
78
+
79
+ # Streams Working Group
80
+
81
+ `readable-stream` is maintained by the Streams Working Group, which
82
+ oversees the development and maintenance of the Streams API within
83
+ Node.js. The responsibilities of the Streams Working Group include:
84
+
85
+ * Addressing stream issues on the Node.js issue tracker.
86
+ * Authoring and editing stream documentation within the Node.js project.
87
+ * Reviewing changes to stream subclasses within the Node.js project.
88
+ * Redirecting changes to streams from the Node.js project to this
89
+ project.
90
+ * Assisting in the implementation of stream providers within Node.js.
91
+ * Recommending versions of `readable-stream` to be included in Node.js.
92
+ * Messaging about the future of streams to give the community advance
93
+ notice of changes.
94
+
95
+ <a name="members"></a>
96
+ ## Team Members
97
+
98
+ * **Calvin Metcalf** ([@calvinmetcalf](https://github.com/calvinmetcalf)) &lt;calvin.metcalf@gmail.com&gt;
99
+ - Release GPG key: F3EF5F62A87FC27A22E643F714CE4FF5015AA242
100
+ * **Mathias Buus** ([@mafintosh](https://github.com/mafintosh)) &lt;mathiasbuus@gmail.com&gt;
101
+ * **Matteo Collina** ([@mcollina](https://github.com/mcollina)) &lt;matteo.collina@gmail.com&gt;
102
+ - Release GPG key: 3ABC01543F22DD2239285CDD818674489FBC127E
103
+ * **Irina Shestak** ([@lrlna](https://github.com/lrlna)) &lt;shestak.irina@gmail.com&gt;
104
+ * **Yoshua Wyuts** ([@yoshuawuyts](https://github.com/yoshuawuyts)) &lt;yoshuawuyts@gmail.com&gt;
105
+
106
+ [sauce]: https://saucelabs.com
node_modules/stream-browserify/node_modules/readable-stream/errors-browser.js ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 'use strict';
2
+
3
+ function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
4
+
5
+ var codes = {};
6
+
7
+ function createErrorType(code, message, Base) {
8
+ if (!Base) {
9
+ Base = Error;
10
+ }
11
+
12
+ function getMessage(arg1, arg2, arg3) {
13
+ if (typeof message === 'string') {
14
+ return message;
15
+ } else {
16
+ return message(arg1, arg2, arg3);
17
+ }
18
+ }
19
+
20
+ var NodeError =
21
+ /*#__PURE__*/
22
+ function (_Base) {
23
+ _inheritsLoose(NodeError, _Base);
24
+
25
+ function NodeError(arg1, arg2, arg3) {
26
+ return _Base.call(this, getMessage(arg1, arg2, arg3)) || this;
27
+ }
28
+
29
+ return NodeError;
30
+ }(Base);
31
+
32
+ NodeError.prototype.name = Base.name;
33
+ NodeError.prototype.code = code;
34
+ codes[code] = NodeError;
35
+ } // https://github.com/nodejs/node/blob/v10.8.0/lib/internal/errors.js
36
+
37
+
38
+ function oneOf(expected, thing) {
39
+ if (Array.isArray(expected)) {
40
+ var len = expected.length;
41
+ expected = expected.map(function (i) {
42
+ return String(i);
43
+ });
44
+
45
+ if (len > 2) {
46
+ return "one of ".concat(thing, " ").concat(expected.slice(0, len - 1).join(', '), ", or ") + expected[len - 1];
47
+ } else if (len === 2) {
48
+ return "one of ".concat(thing, " ").concat(expected[0], " or ").concat(expected[1]);
49
+ } else {
50
+ return "of ".concat(thing, " ").concat(expected[0]);
51
+ }
52
+ } else {
53
+ return "of ".concat(thing, " ").concat(String(expected));
54
+ }
55
+ } // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith
56
+
57
+
58
+ function startsWith(str, search, pos) {
59
+ return str.substr(!pos || pos < 0 ? 0 : +pos, search.length) === search;
60
+ } // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith
61
+
62
+
63
+ function endsWith(str, search, this_len) {
64
+ if (this_len === undefined || this_len > str.length) {
65
+ this_len = str.length;
66
+ }
67
+
68
+ return str.substring(this_len - search.length, this_len) === search;
69
+ } // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes
70
+
71
+
72
+ function includes(str, search, start) {
73
+ if (typeof start !== 'number') {
74
+ start = 0;
75
+ }
76
+
77
+ if (start + search.length > str.length) {
78
+ return false;
79
+ } else {
80
+ return str.indexOf(search, start) !== -1;
81
+ }
82
+ }
83
+
84
+ createErrorType('ERR_INVALID_OPT_VALUE', function (name, value) {
85
+ return 'The value "' + value + '" is invalid for option "' + name + '"';
86
+ }, TypeError);
87
+ createErrorType('ERR_INVALID_ARG_TYPE', function (name, expected, actual) {
88
+ // determiner: 'must be' or 'must not be'
89
+ var determiner;
90
+
91
+ if (typeof expected === 'string' && startsWith(expected, 'not ')) {
92
+ determiner = 'must not be';
93
+ expected = expected.replace(/^not /, '');
94
+ } else {
95
+ determiner = 'must be';
96
+ }
97
+
98
+ var msg;
99
+
100
+ if (endsWith(name, ' argument')) {
101
+ // For cases like 'first argument'
102
+ msg = "The ".concat(name, " ").concat(determiner, " ").concat(oneOf(expected, 'type'));
103
+ } else {
104
+ var type = includes(name, '.') ? 'property' : 'argument';
105
+ msg = "The \"".concat(name, "\" ").concat(type, " ").concat(determiner, " ").concat(oneOf(expected, 'type'));
106
+ }
107
+
108
+ msg += ". Received type ".concat(typeof actual);
109
+ return msg;
110
+ }, TypeError);
111
+ createErrorType('ERR_STREAM_PUSH_AFTER_EOF', 'stream.push() after EOF');
112
+ createErrorType('ERR_METHOD_NOT_IMPLEMENTED', function (name) {
113
+ return 'The ' + name + ' method is not implemented';
114
+ });
115
+ createErrorType('ERR_STREAM_PREMATURE_CLOSE', 'Premature close');
116
+ createErrorType('ERR_STREAM_DESTROYED', function (name) {
117
+ return 'Cannot call ' + name + ' after a stream was destroyed';
118
+ });
119
+ createErrorType('ERR_MULTIPLE_CALLBACK', 'Callback called multiple times');
120
+ createErrorType('ERR_STREAM_CANNOT_PIPE', 'Cannot pipe, not readable');
121
+ createErrorType('ERR_STREAM_WRITE_AFTER_END', 'write after end');
122
+ createErrorType('ERR_STREAM_NULL_VALUES', 'May not write null values to stream', TypeError);
123
+ createErrorType('ERR_UNKNOWN_ENCODING', function (arg) {
124
+ return 'Unknown encoding: ' + arg;
125
+ }, TypeError);
126
+ createErrorType('ERR_STREAM_UNSHIFT_AFTER_END_EVENT', 'stream.unshift() after end event');
127
+ module.exports.codes = codes;
node_modules/stream-browserify/node_modules/readable-stream/errors.js ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 'use strict';
2
+
3
+ const codes = {};
4
+
5
+ function createErrorType(code, message, Base) {
6
+ if (!Base) {
7
+ Base = Error
8
+ }
9
+
10
+ function getMessage (arg1, arg2, arg3) {
11
+ if (typeof message === 'string') {
12
+ return message
13
+ } else {
14
+ return message(arg1, arg2, arg3)
15
+ }
16
+ }
17
+
18
+ class NodeError extends Base {
19
+ constructor (arg1, arg2, arg3) {
20
+ super(getMessage(arg1, arg2, arg3));
21
+ }
22
+ }
23
+
24
+ NodeError.prototype.name = Base.name;
25
+ NodeError.prototype.code = code;
26
+
27
+ codes[code] = NodeError;
28
+ }
29
+
30
+ // https://github.com/nodejs/node/blob/v10.8.0/lib/internal/errors.js
31
+ function oneOf(expected, thing) {
32
+ if (Array.isArray(expected)) {
33
+ const len = expected.length;
34
+ expected = expected.map((i) => String(i));
35
+ if (len > 2) {
36
+ return `one of ${thing} ${expected.slice(0, len - 1).join(', ')}, or ` +
37
+ expected[len - 1];
38
+ } else if (len === 2) {
39
+ return `one of ${thing} ${expected[0]} or ${expected[1]}`;
40
+ } else {
41
+ return `of ${thing} ${expected[0]}`;
42
+ }
43
+ } else {
44
+ return `of ${thing} ${String(expected)}`;
45
+ }
46
+ }
47
+
48
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith
49
+ function startsWith(str, search, pos) {
50
+ return str.substr(!pos || pos < 0 ? 0 : +pos, search.length) === search;
51
+ }
52
+
53
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith
54
+ function endsWith(str, search, this_len) {
55
+ if (this_len === undefined || this_len > str.length) {
56
+ this_len = str.length;
57
+ }
58
+ return str.substring(this_len - search.length, this_len) === search;
59
+ }
60
+
61
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes
62
+ function includes(str, search, start) {
63
+ if (typeof start !== 'number') {
64
+ start = 0;
65
+ }
66
+
67
+ if (start + search.length > str.length) {
68
+ return false;
69
+ } else {
70
+ return str.indexOf(search, start) !== -1;
71
+ }
72
+ }
73
+
74
+ createErrorType('ERR_INVALID_OPT_VALUE', function (name, value) {
75
+ return 'The value "' + value + '" is invalid for option "' + name + '"'
76
+ }, TypeError);
77
+ createErrorType('ERR_INVALID_ARG_TYPE', function (name, expected, actual) {
78
+ // determiner: 'must be' or 'must not be'
79
+ let determiner;
80
+ if (typeof expected === 'string' && startsWith(expected, 'not ')) {
81
+ determiner = 'must not be';
82
+ expected = expected.replace(/^not /, '');
83
+ } else {
84
+ determiner = 'must be';
85
+ }
86
+
87
+ let msg;
88
+ if (endsWith(name, ' argument')) {
89
+ // For cases like 'first argument'
90
+ msg = `The ${name} ${determiner} ${oneOf(expected, 'type')}`;
91
+ } else {
92
+ const type = includes(name, '.') ? 'property' : 'argument';
93
+ msg = `The "${name}" ${type} ${determiner} ${oneOf(expected, 'type')}`;
94
+ }
95
+
96
+ msg += `. Received type ${typeof actual}`;
97
+ return msg;
98
+ }, TypeError);
99
+ createErrorType('ERR_STREAM_PUSH_AFTER_EOF', 'stream.push() after EOF');
100
+ createErrorType('ERR_METHOD_NOT_IMPLEMENTED', function (name) {
101
+ return 'The ' + name + ' method is not implemented'
102
+ });
103
+ createErrorType('ERR_STREAM_PREMATURE_CLOSE', 'Premature close');
104
+ createErrorType('ERR_STREAM_DESTROYED', function (name) {
105
+ return 'Cannot call ' + name + ' after a stream was destroyed';
106
+ });
107
+ createErrorType('ERR_MULTIPLE_CALLBACK', 'Callback called multiple times');
108
+ createErrorType('ERR_STREAM_CANNOT_PIPE', 'Cannot pipe, not readable');
109
+ createErrorType('ERR_STREAM_WRITE_AFTER_END', 'write after end');
110
+ createErrorType('ERR_STREAM_NULL_VALUES', 'May not write null values to stream', TypeError);
111
+ createErrorType('ERR_UNKNOWN_ENCODING', function (arg) {
112
+ return 'Unknown encoding: ' + arg
113
+ }, TypeError);
114
+ createErrorType('ERR_STREAM_UNSHIFT_AFTER_END_EVENT', 'stream.unshift() after end event');
115
+
116
+ module.exports.codes = codes;
node_modules/stream-browserify/node_modules/readable-stream/experimentalWarning.js ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 'use strict'
2
+
3
+ var experimentalWarnings = new Set();
4
+
5
+ function emitExperimentalWarning(feature) {
6
+ if (experimentalWarnings.has(feature)) return;
7
+ var msg = feature + ' is an experimental feature. This feature could ' +
8
+ 'change at any time';
9
+ experimentalWarnings.add(feature);
10
+ process.emitWarning(msg, 'ExperimentalWarning');
11
+ }
12
+
13
+ function noop() {}
14
+
15
+ module.exports.emitExperimentalWarning = process.emitWarning
16
+ ? emitExperimentalWarning
17
+ : noop;
node_modules/stream-browserify/node_modules/readable-stream/lib/_stream_duplex.js ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright Joyent, Inc. and other Node contributors.
2
+ //
3
+ // Permission is hereby granted, free of charge, to any person obtaining a
4
+ // copy of this software and associated documentation files (the
5
+ // "Software"), to deal in the Software without restriction, including
6
+ // without limitation the rights to use, copy, modify, merge, publish,
7
+ // distribute, sublicense, and/or sell copies of the Software, and to permit
8
+ // persons to whom the Software is furnished to do so, subject to the
9
+ // following conditions:
10
+ //
11
+ // The above copyright notice and this permission notice shall be included
12
+ // in all copies or substantial portions of the Software.
13
+ //
14
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15
+ // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17
+ // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18
+ // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19
+ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20
+ // USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ // a duplex stream is just a stream that is both readable and writable.
23
+ // Since JS doesn't have multiple prototypal inheritance, this class
24
+ // prototypally inherits from Readable, and then parasitically from
25
+ // Writable.
26
+
27
+ 'use strict';
28
+
29
+ /*<replacement>*/
30
+ var objectKeys = Object.keys || function (obj) {
31
+ var keys = [];
32
+ for (var key in obj) keys.push(key);
33
+ return keys;
34
+ };
35
+ /*</replacement>*/
36
+
37
+ module.exports = Duplex;
38
+ var Readable = require('./_stream_readable');
39
+ var Writable = require('./_stream_writable');
40
+ require('inherits')(Duplex, Readable);
41
+ {
42
+ // Allow the keys array to be GC'ed.
43
+ var keys = objectKeys(Writable.prototype);
44
+ for (var v = 0; v < keys.length; v++) {
45
+ var method = keys[v];
46
+ if (!Duplex.prototype[method]) Duplex.prototype[method] = Writable.prototype[method];
47
+ }
48
+ }
49
+ function Duplex(options) {
50
+ if (!(this instanceof Duplex)) return new Duplex(options);
51
+ Readable.call(this, options);
52
+ Writable.call(this, options);
53
+ this.allowHalfOpen = true;
54
+ if (options) {
55
+ if (options.readable === false) this.readable = false;
56
+ if (options.writable === false) this.writable = false;
57
+ if (options.allowHalfOpen === false) {
58
+ this.allowHalfOpen = false;
59
+ this.once('end', onend);
60
+ }
61
+ }
62
+ }
63
+ Object.defineProperty(Duplex.prototype, 'writableHighWaterMark', {
64
+ // making it explicit this property is not enumerable
65
+ // because otherwise some prototype manipulation in
66
+ // userland will fail
67
+ enumerable: false,
68
+ get: function get() {
69
+ return this._writableState.highWaterMark;
70
+ }
71
+ });
72
+ Object.defineProperty(Duplex.prototype, 'writableBuffer', {
73
+ // making it explicit this property is not enumerable
74
+ // because otherwise some prototype manipulation in
75
+ // userland will fail
76
+ enumerable: false,
77
+ get: function get() {
78
+ return this._writableState && this._writableState.getBuffer();
79
+ }
80
+ });
81
+ Object.defineProperty(Duplex.prototype, 'writableLength', {
82
+ // making it explicit this property is not enumerable
83
+ // because otherwise some prototype manipulation in
84
+ // userland will fail
85
+ enumerable: false,
86
+ get: function get() {
87
+ return this._writableState.length;
88
+ }
89
+ });
90
+
91
+ // the no-half-open enforcer
92
+ function onend() {
93
+ // If the writable side ended, then we're ok.
94
+ if (this._writableState.ended) return;
95
+
96
+ // no more data can be written.
97
+ // But allow more writes to happen in this tick.
98
+ process.nextTick(onEndNT, this);
99
+ }
100
+ function onEndNT(self) {
101
+ self.end();
102
+ }
103
+ Object.defineProperty(Duplex.prototype, 'destroyed', {
104
+ // making it explicit this property is not enumerable
105
+ // because otherwise some prototype manipulation in
106
+ // userland will fail
107
+ enumerable: false,
108
+ get: function get() {
109
+ if (this._readableState === undefined || this._writableState === undefined) {
110
+ return false;
111
+ }
112
+ return this._readableState.destroyed && this._writableState.destroyed;
113
+ },
114
+ set: function set(value) {
115
+ // we ignore the value if the stream
116
+ // has not been initialized yet
117
+ if (this._readableState === undefined || this._writableState === undefined) {
118
+ return;
119
+ }
120
+
121
+ // backward compatibility, the user is explicitly
122
+ // managing destroyed
123
+ this._readableState.destroyed = value;
124
+ this._writableState.destroyed = value;
125
+ }
126
+ });
node_modules/stream-browserify/node_modules/readable-stream/lib/_stream_passthrough.js ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright Joyent, Inc. and other Node contributors.
2
+ //
3
+ // Permission is hereby granted, free of charge, to any person obtaining a
4
+ // copy of this software and associated documentation files (the
5
+ // "Software"), to deal in the Software without restriction, including
6
+ // without limitation the rights to use, copy, modify, merge, publish,
7
+ // distribute, sublicense, and/or sell copies of the Software, and to permit
8
+ // persons to whom the Software is furnished to do so, subject to the
9
+ // following conditions:
10
+ //
11
+ // The above copyright notice and this permission notice shall be included
12
+ // in all copies or substantial portions of the Software.
13
+ //
14
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15
+ // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17
+ // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18
+ // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19
+ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20
+ // USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ // a passthrough stream.
23
+ // basically just the most minimal sort of Transform stream.
24
+ // Every written chunk gets output as-is.
25
+
26
+ 'use strict';
27
+
28
+ module.exports = PassThrough;
29
+ var Transform = require('./_stream_transform');
30
+ require('inherits')(PassThrough, Transform);
31
+ function PassThrough(options) {
32
+ if (!(this instanceof PassThrough)) return new PassThrough(options);
33
+ Transform.call(this, options);
34
+ }
35
+ PassThrough.prototype._transform = function (chunk, encoding, cb) {
36
+ cb(null, chunk);
37
+ };
node_modules/stream-browserify/node_modules/readable-stream/lib/_stream_readable.js ADDED
@@ -0,0 +1,1027 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright Joyent, Inc. and other Node contributors.
2
+ //
3
+ // Permission is hereby granted, free of charge, to any person obtaining a
4
+ // copy of this software and associated documentation files (the
5
+ // "Software"), to deal in the Software without restriction, including
6
+ // without limitation the rights to use, copy, modify, merge, publish,
7
+ // distribute, sublicense, and/or sell copies of the Software, and to permit
8
+ // persons to whom the Software is furnished to do so, subject to the
9
+ // following conditions:
10
+ //
11
+ // The above copyright notice and this permission notice shall be included
12
+ // in all copies or substantial portions of the Software.
13
+ //
14
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15
+ // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17
+ // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18
+ // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19
+ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20
+ // USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ 'use strict';
23
+
24
+ module.exports = Readable;
25
+
26
+ /*<replacement>*/
27
+ var Duplex;
28
+ /*</replacement>*/
29
+
30
+ Readable.ReadableState = ReadableState;
31
+
32
+ /*<replacement>*/
33
+ var EE = require('events').EventEmitter;
34
+ var EElistenerCount = function EElistenerCount(emitter, type) {
35
+ return emitter.listeners(type).length;
36
+ };
37
+ /*</replacement>*/
38
+
39
+ /*<replacement>*/
40
+ var Stream = require('./internal/streams/stream');
41
+ /*</replacement>*/
42
+
43
+ var Buffer = require('buffer').Buffer;
44
+ var OurUint8Array = (typeof global !== 'undefined' ? global : typeof window !== 'undefined' ? window : typeof self !== 'undefined' ? self : {}).Uint8Array || function () {};
45
+ function _uint8ArrayToBuffer(chunk) {
46
+ return Buffer.from(chunk);
47
+ }
48
+ function _isUint8Array(obj) {
49
+ return Buffer.isBuffer(obj) || obj instanceof OurUint8Array;
50
+ }
51
+
52
+ /*<replacement>*/
53
+ var debugUtil = require('util');
54
+ var debug;
55
+ if (debugUtil && debugUtil.debuglog) {
56
+ debug = debugUtil.debuglog('stream');
57
+ } else {
58
+ debug = function debug() {};
59
+ }
60
+ /*</replacement>*/
61
+
62
+ var BufferList = require('./internal/streams/buffer_list');
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.
73
+ var StringDecoder;
74
+ var createReadableStreamAsyncIterator;
75
+ var from;
76
+ require('inherits')(Readable, Stream);
77
+ var errorOrDestroy = destroyImpl.errorOrDestroy;
78
+ var kProxyEvents = ['error', 'close', 'destroy', 'pause', 'resume'];
79
+ function prependListener(emitter, event, fn) {
80
+ // Sadly this is not cacheable as some libraries bundle their own
81
+ // event emitter implementation with them.
82
+ if (typeof emitter.prependListener === 'function') return emitter.prependListener(event, fn);
83
+
84
+ // This is a hack to make sure that our error handler is attached before any
85
+ // userland ones. NEVER DO THIS. This is here only because this code needs
86
+ // to continue to work with older versions of Node.js that do not include
87
+ // the prependListener() method. The goal is to eventually remove this hack.
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]];
89
+ }
90
+ function ReadableState(options, stream, isDuplex) {
91
+ Duplex = Duplex || require('./_stream_duplex');
92
+ options = options || {};
93
+
94
+ // Duplex streams are both readable and writable, but share
95
+ // the same options object.
96
+ // However, some cases require setting options to different
97
+ // values for the readable and the writable sides of the duplex stream.
98
+ // These options can be provided separately as readableXXX and writableXXX.
99
+ if (typeof isDuplex !== 'boolean') isDuplex = stream instanceof Duplex;
100
+
101
+ // object stream flag. Used to make read(n) ignore n and to
102
+ // make all the buffer merging and length checks go away
103
+ this.objectMode = !!options.objectMode;
104
+ if (isDuplex) this.objectMode = this.objectMode || !!options.readableObjectMode;
105
+
106
+ // the point at which it stops calling _read() to fill the buffer
107
+ // Note: 0 is a valid value, means "don't call _read preemptively ever"
108
+ this.highWaterMark = getHighWaterMark(this, options, 'readableHighWaterMark', isDuplex);
109
+
110
+ // A linked list is used to store data chunks instead of an array because the
111
+ // linked list can remove elements from the beginning faster than
112
+ // array.shift()
113
+ this.buffer = new BufferList();
114
+ this.length = 0;
115
+ this.pipes = null;
116
+ this.pipesCount = 0;
117
+ this.flowing = null;
118
+ this.ended = false;
119
+ this.endEmitted = false;
120
+ this.reading = false;
121
+
122
+ // a flag to be able to tell if the event 'readable'/'data' is emitted
123
+ // immediately, or on a later tick. We set this to true at first, because
124
+ // any actions that shouldn't happen until "later" should generally also
125
+ // not happen before the first read call.
126
+ this.sync = true;
127
+
128
+ // whenever we return null, then we set a flag to say
129
+ // that we're awaiting a 'readable' event emission.
130
+ this.needReadable = false;
131
+ this.emittedReadable = false;
132
+ this.readableListening = false;
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;
141
+
142
+ // has it been destroyed
143
+ this.destroyed = false;
144
+
145
+ // Crypto is kind of old and crusty. Historically, its default string
146
+ // encoding is 'binary' so we have to make this configurable.
147
+ // Everything else in the universe uses 'utf8', though.
148
+ this.defaultEncoding = options.defaultEncoding || 'utf8';
149
+
150
+ // the number of writers that are awaiting a drain event in .pipe()s
151
+ this.awaitDrain = 0;
152
+
153
+ // if true, a maybeReadMore has been scheduled
154
+ this.readingMore = false;
155
+ this.decoder = null;
156
+ this.encoding = null;
157
+ if (options.encoding) {
158
+ if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder;
159
+ this.decoder = new StringDecoder(options.encoding);
160
+ this.encoding = options.encoding;
161
+ }
162
+ }
163
+ function Readable(options) {
164
+ Duplex = Duplex || require('./_stream_duplex');
165
+ if (!(this instanceof Readable)) return new Readable(options);
166
+
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);
171
+
172
+ // legacy
173
+ this.readable = true;
174
+ if (options) {
175
+ if (typeof options.read === 'function') this._read = options.read;
176
+ if (typeof options.destroy === 'function') this._destroy = options.destroy;
177
+ }
178
+ Stream.call(this);
179
+ }
180
+ Object.defineProperty(Readable.prototype, 'destroyed', {
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() {
186
+ if (this._readableState === undefined) {
187
+ return false;
188
+ }
189
+ return this._readableState.destroyed;
190
+ },
191
+ set: function set(value) {
192
+ // we ignore the value if the stream
193
+ // has not been initialized yet
194
+ if (!this._readableState) {
195
+ return;
196
+ }
197
+
198
+ // backward compatibility, the user is explicitly
199
+ // managing destroyed
200
+ this._readableState.destroyed = value;
201
+ }
202
+ });
203
+ Readable.prototype.destroy = destroyImpl.destroy;
204
+ Readable.prototype._undestroy = destroyImpl.undestroy;
205
+ Readable.prototype._destroy = function (err, cb) {
206
+ cb(err);
207
+ };
208
+
209
+ // Manually shove something into the read() buffer.
210
+ // This returns true if the highWaterMark has not been hit yet,
211
+ // similar to how Writable.write() returns true if you should
212
+ // write() some more.
213
+ Readable.prototype.push = function (chunk, encoding) {
214
+ var state = this._readableState;
215
+ var skipChunkCheck;
216
+ if (!state.objectMode) {
217
+ if (typeof chunk === 'string') {
218
+ encoding = encoding || state.defaultEncoding;
219
+ if (encoding !== state.encoding) {
220
+ chunk = Buffer.from(chunk, encoding);
221
+ encoding = '';
222
+ }
223
+ skipChunkCheck = true;
224
+ }
225
+ } else {
226
+ skipChunkCheck = true;
227
+ }
228
+ return readableAddChunk(this, chunk, encoding, false, skipChunkCheck);
229
+ };
230
+
231
+ // Unshift should *always* be something directly out of read()
232
+ Readable.prototype.unshift = function (chunk) {
233
+ return readableAddChunk(this, chunk, null, true, false);
234
+ };
235
+ function readableAddChunk(stream, chunk, encoding, addToFront, skipChunkCheck) {
236
+ debug('readableAddChunk', chunk);
237
+ var state = stream._readableState;
238
+ if (chunk === null) {
239
+ state.reading = false;
240
+ onEofChunk(stream, state);
241
+ } else {
242
+ var er;
243
+ if (!skipChunkCheck) er = chunkInvalid(state, chunk);
244
+ if (er) {
245
+ errorOrDestroy(stream, er);
246
+ } else if (state.objectMode || chunk && chunk.length > 0) {
247
+ if (typeof chunk !== 'string' && !state.objectMode && Object.getPrototypeOf(chunk) !== Buffer.prototype) {
248
+ chunk = _uint8ArrayToBuffer(chunk);
249
+ }
250
+ if (addToFront) {
251
+ if (state.endEmitted) errorOrDestroy(stream, new ERR_STREAM_UNSHIFT_AFTER_END_EVENT());else addChunk(stream, state, chunk, true);
252
+ } else if (state.ended) {
253
+ errorOrDestroy(stream, new ERR_STREAM_PUSH_AFTER_EOF());
254
+ } else if (state.destroyed) {
255
+ return false;
256
+ } else {
257
+ state.reading = false;
258
+ if (state.decoder && !encoding) {
259
+ chunk = state.decoder.write(chunk);
260
+ if (state.objectMode || chunk.length !== 0) addChunk(stream, state, chunk, false);else maybeReadMore(stream, state);
261
+ } else {
262
+ addChunk(stream, state, chunk, false);
263
+ }
264
+ }
265
+ } else if (!addToFront) {
266
+ state.reading = false;
267
+ maybeReadMore(stream, state);
268
+ }
269
+ }
270
+
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);
275
+ }
276
+ function addChunk(stream, state, chunk, addToFront) {
277
+ if (state.flowing && state.length === 0 && !state.sync) {
278
+ state.awaitDrain = 0;
279
+ stream.emit('data', chunk);
280
+ } else {
281
+ // update the buffer info.
282
+ state.length += state.objectMode ? 1 : chunk.length;
283
+ if (addToFront) state.buffer.unshift(chunk);else state.buffer.push(chunk);
284
+ if (state.needReadable) emitReadable(stream);
285
+ }
286
+ maybeReadMore(stream, state);
287
+ }
288
+ function chunkInvalid(state, chunk) {
289
+ var er;
290
+ if (!_isUint8Array(chunk) && typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) {
291
+ er = new ERR_INVALID_ARG_TYPE('chunk', ['string', 'Buffer', 'Uint8Array'], chunk);
292
+ }
293
+ return er;
294
+ }
295
+ Readable.prototype.isPaused = function () {
296
+ return this._readableState.flowing === false;
297
+ };
298
+
299
+ // backwards compatibility.
300
+ Readable.prototype.setEncoding = function (enc) {
301
+ if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder;
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;
317
+ return this;
318
+ };
319
+
320
+ // Don't raise the hwm > 1GB
321
+ var MAX_HWM = 0x40000000;
322
+ function computeNewHighWaterMark(n) {
323
+ if (n >= MAX_HWM) {
324
+ // TODO(ronag): Throw ERR_VALUE_OUT_OF_RANGE.
325
+ n = MAX_HWM;
326
+ } else {
327
+ // Get the next highest power of 2 to prevent increasing hwm excessively in
328
+ // tiny amounts
329
+ n--;
330
+ n |= n >>> 1;
331
+ n |= n >>> 2;
332
+ n |= n >>> 4;
333
+ n |= n >>> 8;
334
+ n |= n >>> 16;
335
+ n++;
336
+ }
337
+ return n;
338
+ }
339
+
340
+ // This function is designed to be inlinable, so please take care when making
341
+ // changes to the function body.
342
+ function howMuchToRead(n, state) {
343
+ if (n <= 0 || state.length === 0 && state.ended) return 0;
344
+ if (state.objectMode) return 1;
345
+ if (n !== n) {
346
+ // Only flow one buffer at a time
347
+ if (state.flowing && state.length) return state.buffer.head.data.length;else return state.length;
348
+ }
349
+ // If we're asking for more than the current hwm, then raise the hwm.
350
+ if (n > state.highWaterMark) state.highWaterMark = computeNewHighWaterMark(n);
351
+ if (n <= state.length) return n;
352
+ // Don't have enough
353
+ if (!state.ended) {
354
+ state.needReadable = true;
355
+ return 0;
356
+ }
357
+ return state.length;
358
+ }
359
+
360
+ // you can override either this method, or the async _read(n) below.
361
+ Readable.prototype.read = function (n) {
362
+ debug('read', n);
363
+ n = parseInt(n, 10);
364
+ var state = this._readableState;
365
+ var nOrig = n;
366
+ if (n !== 0) state.emittedReadable = false;
367
+
368
+ // if we're doing read(0) to trigger a readable event, but we
369
+ // already have a bunch of data in the buffer, then just trigger
370
+ // the 'readable' event and move on.
371
+ if (n === 0 && state.needReadable && ((state.highWaterMark !== 0 ? state.length >= state.highWaterMark : state.length > 0) || state.ended)) {
372
+ debug('read: emitReadable', state.length, state.ended);
373
+ if (state.length === 0 && state.ended) endReadable(this);else emitReadable(this);
374
+ return null;
375
+ }
376
+ n = howMuchToRead(n, state);
377
+
378
+ // if we've ended, and we're now clear, then finish it up.
379
+ if (n === 0 && state.ended) {
380
+ if (state.length === 0) endReadable(this);
381
+ return null;
382
+ }
383
+
384
+ // All the actual chunk generation logic needs to be
385
+ // *below* the call to _read. The reason is that in certain
386
+ // synthetic stream cases, such as passthrough streams, _read
387
+ // may be a completely synchronous operation which may change
388
+ // the state of the read buffer, providing enough data when
389
+ // before there was *not* enough.
390
+ //
391
+ // So, the steps are:
392
+ // 1. Figure out what the state of things will be after we do
393
+ // a read from the buffer.
394
+ //
395
+ // 2. If that resulting state will trigger a _read, then call _read.
396
+ // Note that this may be asynchronous, or synchronous. Yes, it is
397
+ // deeply ugly to write APIs this way, but that still doesn't mean
398
+ // that the Readable class should behave improperly, as streams are
399
+ // designed to be sync/async agnostic.
400
+ // Take note if the _read call is sync or async (ie, if the read call
401
+ // has returned yet), so that we know whether or not it's safe to emit
402
+ // 'readable' etc.
403
+ //
404
+ // 3. Actually pull the requested chunks out of the buffer and return.
405
+
406
+ // if we need a readable event, then we need to do some reading.
407
+ var doRead = state.needReadable;
408
+ debug('need readable', doRead);
409
+
410
+ // if we currently have less than the highWaterMark, then also read some
411
+ if (state.length === 0 || state.length - n < state.highWaterMark) {
412
+ doRead = true;
413
+ debug('length less than watermark', doRead);
414
+ }
415
+
416
+ // however, if we've ended, then there's no point, and if we're already
417
+ // reading, then it's unnecessary.
418
+ if (state.ended || state.reading) {
419
+ doRead = false;
420
+ debug('reading or ended', doRead);
421
+ } else if (doRead) {
422
+ debug('do read');
423
+ state.reading = true;
424
+ state.sync = true;
425
+ // if the length is currently zero, then we *need* a readable event.
426
+ if (state.length === 0) state.needReadable = true;
427
+ // call internal read method
428
+ this._read(state.highWaterMark);
429
+ state.sync = false;
430
+ // If _read pushed data synchronously, then `reading` will be false,
431
+ // and we need to re-evaluate how much data we can return to the user.
432
+ if (!state.reading) n = howMuchToRead(nOrig, state);
433
+ }
434
+ var ret;
435
+ if (n > 0) ret = fromList(n, state);else ret = null;
436
+ if (ret === null) {
437
+ state.needReadable = state.length <= state.highWaterMark;
438
+ n = 0;
439
+ } else {
440
+ state.length -= n;
441
+ state.awaitDrain = 0;
442
+ }
443
+ if (state.length === 0) {
444
+ // If we have nothing in the buffer, then we want to know
445
+ // as soon as we *do* get something into the buffer.
446
+ if (!state.ended) state.needReadable = true;
447
+
448
+ // If we tried to read() past the EOF, then emit end on the next tick.
449
+ if (nOrig !== n && state.ended) endReadable(this);
450
+ }
451
+ if (ret !== null) this.emit('data', ret);
452
+ return ret;
453
+ };
454
+ function onEofChunk(stream, state) {
455
+ debug('onEofChunk');
456
+ if (state.ended) return;
457
+ if (state.decoder) {
458
+ var chunk = state.decoder.end();
459
+ if (chunk && chunk.length) {
460
+ state.buffer.push(chunk);
461
+ state.length += state.objectMode ? 1 : chunk.length;
462
+ }
463
+ }
464
+ state.ended = true;
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
+ }
478
+ }
479
+
480
+ // Don't emit readable right away in sync mode, because this can trigger
481
+ // another read() call => stack overflow. This way, it might trigger
482
+ // a nextTick recursion warning, but that's not so bad.
483
+ function emitReadable(stream) {
484
+ var state = stream._readableState;
485
+ debug('emitReadable', state.needReadable, state.emittedReadable);
486
+ state.needReadable = false;
487
+ if (!state.emittedReadable) {
488
+ debug('emitReadable', state.flowing);
489
+ state.emittedReadable = true;
490
+ process.nextTick(emitReadable_, stream);
491
+ }
492
+ }
493
+ function emitReadable_(stream) {
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;
508
+ flow(stream);
509
+ }
510
+
511
+ // at this point, the user has presumably seen the 'readable' event,
512
+ // and called read() to consume some data. that may have triggered
513
+ // in turn another _read(n) call, in which case reading = true if
514
+ // it's in progress.
515
+ // However, if we're not ended, or reading, and the length < hwm,
516
+ // then go ahead and try to read some more preemptively.
517
+ function maybeReadMore(stream, state) {
518
+ if (!state.readingMore) {
519
+ state.readingMore = true;
520
+ process.nextTick(maybeReadMore_, stream, state);
521
+ }
522
+ }
523
+ function maybeReadMore_(stream, state) {
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;
549
+ debug('maybeReadMore read 0');
550
+ stream.read(0);
551
+ if (len === state.length)
552
+ // didn't get any data, stop spinning.
553
+ break;
554
+ }
555
+ state.readingMore = false;
556
+ }
557
+
558
+ // abstract method. to be overridden in specific implementation classes.
559
+ // call cb(er, data) where data is <= n in length.
560
+ // for virtual (non-string, non-buffer) streams, "length" is somewhat
561
+ // arbitrary, and perhaps not very meaningful.
562
+ Readable.prototype._read = function (n) {
563
+ errorOrDestroy(this, new ERR_METHOD_NOT_IMPLEMENTED('_read()'));
564
+ };
565
+ Readable.prototype.pipe = function (dest, pipeOpts) {
566
+ var src = this;
567
+ var state = this._readableState;
568
+ switch (state.pipesCount) {
569
+ case 0:
570
+ state.pipes = dest;
571
+ break;
572
+ case 1:
573
+ state.pipes = [state.pipes, dest];
574
+ break;
575
+ default:
576
+ state.pipes.push(dest);
577
+ break;
578
+ }
579
+ state.pipesCount += 1;
580
+ debug('pipe count=%d opts=%j', state.pipesCount, pipeOpts);
581
+ var doEnd = (!pipeOpts || pipeOpts.end !== false) && dest !== process.stdout && dest !== process.stderr;
582
+ var endFn = doEnd ? onend : unpipe;
583
+ if (state.endEmitted) process.nextTick(endFn);else src.once('end', endFn);
584
+ dest.on('unpipe', onunpipe);
585
+ function onunpipe(readable, unpipeInfo) {
586
+ debug('onunpipe');
587
+ if (readable === src) {
588
+ if (unpipeInfo && unpipeInfo.hasUnpiped === false) {
589
+ unpipeInfo.hasUnpiped = true;
590
+ cleanup();
591
+ }
592
+ }
593
+ }
594
+ function onend() {
595
+ debug('onend');
596
+ dest.end();
597
+ }
598
+
599
+ // when the dest drains, it reduces the awaitDrain counter
600
+ // on the source. This would be more elegant with a .once()
601
+ // handler in flow(), but adding and removing repeatedly is
602
+ // too slow.
603
+ var ondrain = pipeOnDrain(src);
604
+ dest.on('drain', ondrain);
605
+ var cleanedUp = false;
606
+ function cleanup() {
607
+ debug('cleanup');
608
+ // cleanup event handlers once the pipe is broken
609
+ dest.removeListener('close', onclose);
610
+ dest.removeListener('finish', onfinish);
611
+ dest.removeListener('drain', ondrain);
612
+ dest.removeListener('error', onerror);
613
+ dest.removeListener('unpipe', onunpipe);
614
+ src.removeListener('end', onend);
615
+ src.removeListener('end', unpipe);
616
+ src.removeListener('data', ondata);
617
+ cleanedUp = true;
618
+
619
+ // if the reader is waiting for a drain event from this
620
+ // specific writer, then it would cause it to never start
621
+ // flowing again.
622
+ // So, if this is awaiting a drain, then we just call it now.
623
+ // If we don't know, then assume that we are waiting for one.
624
+ if (state.awaitDrain && (!dest._writableState || dest._writableState.needDrain)) ondrain();
625
+ }
626
+ src.on('data', ondata);
627
+ function ondata(chunk) {
628
+ debug('ondata');
629
+ var ret = dest.write(chunk);
630
+ debug('dest.write', ret);
631
+ if (ret === false) {
632
+ // If the user unpiped during `dest.write()`, it is possible
633
+ // to get stuck in a permanently paused state if that write
634
+ // also returned false.
635
+ // => Check whether `dest` is still a piping destination.
636
+ if ((state.pipesCount === 1 && state.pipes === dest || state.pipesCount > 1 && indexOf(state.pipes, dest) !== -1) && !cleanedUp) {
637
+ debug('false write response, pause', state.awaitDrain);
638
+ state.awaitDrain++;
639
+ }
640
+ src.pause();
641
+ }
642
+ }
643
+
644
+ // if the dest has an error, then stop piping into it.
645
+ // however, don't suppress the throwing behavior for this.
646
+ function onerror(er) {
647
+ debug('onerror', er);
648
+ unpipe();
649
+ dest.removeListener('error', onerror);
650
+ if (EElistenerCount(dest, 'error') === 0) errorOrDestroy(dest, er);
651
+ }
652
+
653
+ // Make sure our error handler is attached before userland ones.
654
+ prependListener(dest, 'error', onerror);
655
+
656
+ // Both close and finish should trigger unpipe, but only once.
657
+ function onclose() {
658
+ dest.removeListener('finish', onfinish);
659
+ unpipe();
660
+ }
661
+ dest.once('close', onclose);
662
+ function onfinish() {
663
+ debug('onfinish');
664
+ dest.removeListener('close', onclose);
665
+ unpipe();
666
+ }
667
+ dest.once('finish', onfinish);
668
+ function unpipe() {
669
+ debug('unpipe');
670
+ src.unpipe(dest);
671
+ }
672
+
673
+ // tell the dest that it's being piped to
674
+ dest.emit('pipe', src);
675
+
676
+ // start the flow if it hasn't been started already.
677
+ if (!state.flowing) {
678
+ debug('pipe resume');
679
+ src.resume();
680
+ }
681
+ return dest;
682
+ };
683
+ function pipeOnDrain(src) {
684
+ return function pipeOnDrainFunctionResult() {
685
+ var state = src._readableState;
686
+ debug('pipeOnDrain', state.awaitDrain);
687
+ if (state.awaitDrain) state.awaitDrain--;
688
+ if (state.awaitDrain === 0 && EElistenerCount(src, 'data')) {
689
+ state.flowing = true;
690
+ flow(src);
691
+ }
692
+ };
693
+ }
694
+ Readable.prototype.unpipe = function (dest) {
695
+ var state = this._readableState;
696
+ var unpipeInfo = {
697
+ hasUnpiped: false
698
+ };
699
+
700
+ // if we're not piping anywhere, then do nothing.
701
+ if (state.pipesCount === 0) return this;
702
+
703
+ // just one destination. most common case.
704
+ if (state.pipesCount === 1) {
705
+ // passed in one, but it's not the right one.
706
+ if (dest && dest !== state.pipes) return this;
707
+ if (!dest) dest = state.pipes;
708
+
709
+ // got a match.
710
+ state.pipes = null;
711
+ state.pipesCount = 0;
712
+ state.flowing = false;
713
+ if (dest) dest.emit('unpipe', this, unpipeInfo);
714
+ return this;
715
+ }
716
+
717
+ // slow case. multiple pipe destinations.
718
+
719
+ if (!dest) {
720
+ // remove all.
721
+ var dests = state.pipes;
722
+ var len = state.pipesCount;
723
+ state.pipes = null;
724
+ state.pipesCount = 0;
725
+ state.flowing = false;
726
+ for (var i = 0; i < len; i++) dests[i].emit('unpipe', this, {
727
+ hasUnpiped: false
728
+ });
729
+ return this;
730
+ }
731
+
732
+ // try to find the right one.
733
+ var index = indexOf(state.pipes, dest);
734
+ if (index === -1) return this;
735
+ state.pipes.splice(index, 1);
736
+ state.pipesCount -= 1;
737
+ if (state.pipesCount === 1) state.pipes = state.pipes[0];
738
+ dest.emit('unpipe', this, unpipeInfo);
739
+ return this;
740
+ };
741
+
742
+ // set up data events if they are asked for
743
+ // Ensure readable listeners eventually get something
744
+ Readable.prototype.on = function (ev, fn) {
745
+ var res = Stream.prototype.on.call(this, ev, fn);
746
+ var state = this._readableState;
747
+ if (ev === 'data') {
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();
754
+ } else if (ev === 'readable') {
755
+ if (!state.endEmitted && !state.readableListening) {
756
+ state.readableListening = state.needReadable = true;
757
+ state.flowing = false;
758
+ state.emittedReadable = false;
759
+ debug('on readable', state.length, state.reading);
760
+ if (state.length) {
761
+ emitReadable(this);
762
+ } else if (!state.reading) {
763
+ process.nextTick(nReadingNextTick, this);
764
+ }
765
+ }
766
+ }
767
+ return res;
768
+ };
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;
803
+
804
+ // crude way to check if we should resume
805
+ } else if (self.listenerCount('data') > 0) {
806
+ self.resume();
807
+ }
808
+ }
809
+ function nReadingNextTick(self) {
810
+ debug('readable nexttick read 0');
811
+ self.read(0);
812
+ }
813
+
814
+ // pause() and resume() are remnants of the legacy readable stream API
815
+ // If the user uses them, then switch into old mode.
816
+ Readable.prototype.resume = function () {
817
+ var state = this._readableState;
818
+ if (!state.flowing) {
819
+ debug('resume');
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;
824
+ resume(this, state);
825
+ }
826
+ state.paused = false;
827
+ return this;
828
+ };
829
+ function resume(stream, state) {
830
+ if (!state.resumeScheduled) {
831
+ state.resumeScheduled = true;
832
+ process.nextTick(resume_, stream, state);
833
+ }
834
+ }
835
+ function resume_(stream, state) {
836
+ debug('resume', state.reading);
837
+ if (!state.reading) {
838
+ stream.read(0);
839
+ }
840
+ state.resumeScheduled = false;
841
+ stream.emit('resume');
842
+ flow(stream);
843
+ if (state.flowing && !state.reading) stream.read(0);
844
+ }
845
+ Readable.prototype.pause = function () {
846
+ debug('call pause flowing=%j', this._readableState.flowing);
847
+ if (this._readableState.flowing !== false) {
848
+ debug('pause');
849
+ this._readableState.flowing = false;
850
+ this.emit('pause');
851
+ }
852
+ this._readableState.paused = true;
853
+ return this;
854
+ };
855
+ function flow(stream) {
856
+ var state = stream._readableState;
857
+ debug('flow', state.flowing);
858
+ while (state.flowing && stream.read() !== null);
859
+ }
860
+
861
+ // wrap an old-style stream as the async data source.
862
+ // This is *not* part of the readable stream interface.
863
+ // It is an ugly unfortunate mess of history.
864
+ Readable.prototype.wrap = function (stream) {
865
+ var _this = this;
866
+ var state = this._readableState;
867
+ var paused = false;
868
+ stream.on('end', function () {
869
+ debug('wrapped end');
870
+ if (state.decoder && !state.ended) {
871
+ var chunk = state.decoder.end();
872
+ if (chunk && chunk.length) _this.push(chunk);
873
+ }
874
+ _this.push(null);
875
+ });
876
+ stream.on('data', function (chunk) {
877
+ debug('wrapped data');
878
+ if (state.decoder) chunk = state.decoder.write(chunk);
879
+
880
+ // don't skip over falsy values in objectMode
881
+ if (state.objectMode && (chunk === null || chunk === undefined)) return;else if (!state.objectMode && (!chunk || !chunk.length)) return;
882
+ var ret = _this.push(chunk);
883
+ if (!ret) {
884
+ paused = true;
885
+ stream.pause();
886
+ }
887
+ });
888
+
889
+ // proxy all the other methods.
890
+ // important when wrapping filters and duplexes.
891
+ for (var i in stream) {
892
+ if (this[i] === undefined && typeof stream[i] === 'function') {
893
+ this[i] = function methodWrap(method) {
894
+ return function methodWrapReturnFunction() {
895
+ return stream[method].apply(stream, arguments);
896
+ };
897
+ }(i);
898
+ }
899
+ }
900
+
901
+ // proxy certain important events.
902
+ for (var n = 0; n < kProxyEvents.length; n++) {
903
+ stream.on(kProxyEvents[n], this.emit.bind(this, kProxyEvents[n]));
904
+ }
905
+
906
+ // when we try to consume some more bytes, simply unpause the
907
+ // underlying stream.
908
+ this._read = function (n) {
909
+ debug('wrapped _read', n);
910
+ if (paused) {
911
+ paused = false;
912
+ stream.resume();
913
+ }
914
+ };
915
+ return this;
916
+ };
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
+ }
925
+ Object.defineProperty(Readable.prototype, 'readableHighWaterMark', {
926
+ // making it explicit this property is not enumerable
927
+ // because otherwise some prototype manipulation in
928
+ // userland will fail
929
+ enumerable: false,
930
+ get: function get() {
931
+ return this._readableState.highWaterMark;
932
+ }
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
+ });
957
+
958
+ // exposed for testing purposes only.
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
+ });
969
+
970
+ // Pluck off n bytes from an array of buffers.
971
+ // Length is the combined lengths of all the buffers in the list.
972
+ // This function is designed to be inlinable, so please take care when making
973
+ // changes to the function body.
974
+ function fromList(n, state) {
975
+ // nothing buffered
976
+ if (state.length === 0) return null;
977
+ var ret;
978
+ if (state.objectMode) ret = state.buffer.shift();else if (!n || n >= state.length) {
979
+ // read it all, truncate the list
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);
981
+ state.buffer.clear();
982
+ } else {
983
+ // read part of list
984
+ ret = state.buffer.consume(n, state.decoder);
985
+ }
986
+ return ret;
987
+ }
988
+ function endReadable(stream) {
989
+ var state = stream._readableState;
990
+ debug('endReadable', state.endEmitted);
991
+ if (!state.endEmitted) {
992
+ state.ended = true;
993
+ process.nextTick(endReadableNT, state, stream);
994
+ }
995
+ }
996
+ function endReadableNT(state, stream) {
997
+ debug('endReadableNT', state.endEmitted, state.length);
998
+
999
+ // Check that we didn't get one last unshift.
1000
+ if (!state.endEmitted && state.length === 0) {
1001
+ state.endEmitted = true;
1002
+ stream.readable = false;
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
+ }
1012
+ }
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
+ }
1022
+ function indexOf(xs, x) {
1023
+ for (var i = 0, l = xs.length; i < l; i++) {
1024
+ if (xs[i] === x) return i;
1025
+ }
1026
+ return -1;
1027
+ }
node_modules/stream-browserify/node_modules/readable-stream/lib/_stream_transform.js ADDED
@@ -0,0 +1,190 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright Joyent, Inc. and other Node contributors.
2
+ //
3
+ // Permission is hereby granted, free of charge, to any person obtaining a
4
+ // copy of this software and associated documentation files (the
5
+ // "Software"), to deal in the Software without restriction, including
6
+ // without limitation the rights to use, copy, modify, merge, publish,
7
+ // distribute, sublicense, and/or sell copies of the Software, and to permit
8
+ // persons to whom the Software is furnished to do so, subject to the
9
+ // following conditions:
10
+ //
11
+ // The above copyright notice and this permission notice shall be included
12
+ // in all copies or substantial portions of the Software.
13
+ //
14
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15
+ // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17
+ // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18
+ // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19
+ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20
+ // USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ // a transform stream is a readable/writable stream where you do
23
+ // something with the data. Sometimes it's called a "filter",
24
+ // but that's not a great name for it, since that implies a thing where
25
+ // some bits pass through, and others are simply ignored. (That would
26
+ // be a valid example of a transform, of course.)
27
+ //
28
+ // While the output is causally related to the input, it's not a
29
+ // necessarily symmetric or synchronous transformation. For example,
30
+ // a zlib stream might take multiple plain-text writes(), and then
31
+ // emit a single compressed chunk some time in the future.
32
+ //
33
+ // Here's how this works:
34
+ //
35
+ // The Transform stream has all the aspects of the readable and writable
36
+ // stream classes. When you write(chunk), that calls _write(chunk,cb)
37
+ // internally, and returns false if there's a lot of pending writes
38
+ // buffered up. When you call read(), that calls _read(n) until
39
+ // there's enough pending readable data buffered up.
40
+ //
41
+ // In a transform stream, the written data is placed in a buffer. When
42
+ // _read(n) is called, it transforms the queued up data, calling the
43
+ // buffered _write cb's as it consumes chunks. If consuming a single
44
+ // written chunk would result in multiple output chunks, then the first
45
+ // outputted bit calls the readcb, and subsequent chunks just go into
46
+ // the read buffer, and will cause it to emit 'readable' if necessary.
47
+ //
48
+ // This way, back-pressure is actually determined by the reading side,
49
+ // since _read has to be called to start processing a new chunk. However,
50
+ // a pathological inflate type of transform can cause excessive buffering
51
+ // here. For example, imagine a stream where every byte of input is
52
+ // interpreted as an integer from 0-255, and then results in that many
53
+ // bytes of output. Writing the 4 bytes {ff,ff,ff,ff} would result in
54
+ // 1kb of data being output. In this case, you could write a very small
55
+ // amount of input, and end up with a very large amount of output. In
56
+ // such a pathological inflating mechanism, there'd be no way to tell
57
+ // the system to stop doing the transform. A single 4MB write could
58
+ // cause the system to run out of memory.
59
+ //
60
+ // However, even in such a pathological case, only a single written chunk
61
+ // would be consumed, and then the rest would wait (un-transformed) until
62
+ // the results of the previous transformed chunk were consumed.
63
+
64
+ 'use strict';
65
+
66
+ module.exports = Transform;
67
+ var _require$codes = require('../errors').codes,
68
+ ERR_METHOD_NOT_IMPLEMENTED = _require$codes.ERR_METHOD_NOT_IMPLEMENTED,
69
+ ERR_MULTIPLE_CALLBACK = _require$codes.ERR_MULTIPLE_CALLBACK,
70
+ ERR_TRANSFORM_ALREADY_TRANSFORMING = _require$codes.ERR_TRANSFORM_ALREADY_TRANSFORMING,
71
+ ERR_TRANSFORM_WITH_LENGTH_0 = _require$codes.ERR_TRANSFORM_WITH_LENGTH_0;
72
+ var Duplex = require('./_stream_duplex');
73
+ require('inherits')(Transform, Duplex);
74
+ function afterTransform(er, data) {
75
+ var ts = this._transformState;
76
+ ts.transforming = false;
77
+ var cb = ts.writecb;
78
+ if (cb === null) {
79
+ return this.emit('error', new ERR_MULTIPLE_CALLBACK());
80
+ }
81
+ ts.writechunk = null;
82
+ ts.writecb = null;
83
+ if (data != null)
84
+ // single equals check for both `null` and `undefined`
85
+ this.push(data);
86
+ cb(er);
87
+ var rs = this._readableState;
88
+ rs.reading = false;
89
+ if (rs.needReadable || rs.length < rs.highWaterMark) {
90
+ this._read(rs.highWaterMark);
91
+ }
92
+ }
93
+ function Transform(options) {
94
+ if (!(this instanceof Transform)) return new Transform(options);
95
+ Duplex.call(this, options);
96
+ this._transformState = {
97
+ afterTransform: afterTransform.bind(this),
98
+ needTransform: false,
99
+ transforming: false,
100
+ writecb: null,
101
+ writechunk: null,
102
+ writeencoding: null
103
+ };
104
+
105
+ // start out asking for a readable event once data is transformed.
106
+ this._readableState.needReadable = true;
107
+
108
+ // we have implemented the _read method, and done the other things
109
+ // that Readable wants before the first _read call, so unset the
110
+ // sync guard flag.
111
+ this._readableState.sync = false;
112
+ if (options) {
113
+ if (typeof options.transform === 'function') this._transform = options.transform;
114
+ if (typeof options.flush === 'function') this._flush = options.flush;
115
+ }
116
+
117
+ // When the writable side finishes, then flush out anything remaining.
118
+ this.on('prefinish', prefinish);
119
+ }
120
+ function prefinish() {
121
+ var _this = this;
122
+ if (typeof this._flush === 'function' && !this._readableState.destroyed) {
123
+ this._flush(function (er, data) {
124
+ done(_this, er, data);
125
+ });
126
+ } else {
127
+ done(this, null, null);
128
+ }
129
+ }
130
+ Transform.prototype.push = function (chunk, encoding) {
131
+ this._transformState.needTransform = false;
132
+ return Duplex.prototype.push.call(this, chunk, encoding);
133
+ };
134
+
135
+ // This is the part where you do stuff!
136
+ // override this function in implementation classes.
137
+ // 'chunk' is an input chunk.
138
+ //
139
+ // Call `push(newChunk)` to pass along transformed output
140
+ // to the readable side. You may call 'push' zero or more times.
141
+ //
142
+ // Call `cb(err)` when you are done with this chunk. If you pass
143
+ // an error, then that'll put the hurt on the whole operation. If you
144
+ // never call cb(), then you'll never get another chunk.
145
+ Transform.prototype._transform = function (chunk, encoding, cb) {
146
+ cb(new ERR_METHOD_NOT_IMPLEMENTED('_transform()'));
147
+ };
148
+ Transform.prototype._write = function (chunk, encoding, cb) {
149
+ var ts = this._transformState;
150
+ ts.writecb = cb;
151
+ ts.writechunk = chunk;
152
+ ts.writeencoding = encoding;
153
+ if (!ts.transforming) {
154
+ var rs = this._readableState;
155
+ if (ts.needTransform || rs.needReadable || rs.length < rs.highWaterMark) this._read(rs.highWaterMark);
156
+ }
157
+ };
158
+
159
+ // Doesn't matter what the args are here.
160
+ // _transform does all the work.
161
+ // That we got here means that the readable side wants more data.
162
+ Transform.prototype._read = function (n) {
163
+ var ts = this._transformState;
164
+ if (ts.writechunk !== null && !ts.transforming) {
165
+ ts.transforming = true;
166
+ this._transform(ts.writechunk, ts.writeencoding, ts.afterTransform);
167
+ } else {
168
+ // mark that we need a transform, so that any data that comes in
169
+ // will get processed, now that we've asked for it.
170
+ ts.needTransform = true;
171
+ }
172
+ };
173
+ Transform.prototype._destroy = function (err, cb) {
174
+ Duplex.prototype._destroy.call(this, err, function (err2) {
175
+ cb(err2);
176
+ });
177
+ };
178
+ function done(stream, er, data) {
179
+ if (er) return stream.emit('error', er);
180
+ if (data != null)
181
+ // single equals check for both `null` and `undefined`
182
+ stream.push(data);
183
+
184
+ // TODO(BridgeAR): Write a test for these two error cases
185
+ // if there's nothing in the write buffer, then that means
186
+ // that nothing more will ever be provided
187
+ if (stream._writableState.length) throw new ERR_TRANSFORM_WITH_LENGTH_0();
188
+ if (stream._transformState.transforming) throw new ERR_TRANSFORM_ALREADY_TRANSFORMING();
189
+ return stream.push(null);
190
+ }
node_modules/stream-browserify/node_modules/readable-stream/lib/_stream_writable.js ADDED
@@ -0,0 +1,641 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Copyright Joyent, Inc. and other Node contributors.
2
+ //
3
+ // Permission is hereby granted, free of charge, to any person obtaining a
4
+ // copy of this software and associated documentation files (the
5
+ // "Software"), to deal in the Software without restriction, including
6
+ // without limitation the rights to use, copy, modify, merge, publish,
7
+ // distribute, sublicense, and/or sell copies of the Software, and to permit
8
+ // persons to whom the Software is furnished to do so, subject to the
9
+ // following conditions:
10
+ //
11
+ // The above copyright notice and this permission notice shall be included
12
+ // in all copies or substantial portions of the Software.
13
+ //
14
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15
+ // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17
+ // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18
+ // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19
+ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20
+ // USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ // A bit simpler than readable streams.
23
+ // Implement an async ._write(chunk, encoding, cb), and it'll handle all
24
+ // the drain event emission and buffering.
25
+
26
+ 'use strict';
27
+
28
+ module.exports = Writable;
29
+
30
+ /* <replacement> */
31
+ function WriteReq(chunk, encoding, cb) {
32
+ this.chunk = chunk;
33
+ this.encoding = encoding;
34
+ this.callback = cb;
35
+ this.next = null;
36
+ }
37
+
38
+ // It seems a linked list but it is not
39
+ // there will be only 2 of these for each stream
40
+ function CorkedRequest(state) {
41
+ var _this = this;
42
+ this.next = null;
43
+ this.entry = null;
44
+ this.finish = function () {
45
+ onCorkedFinish(_this, state);
46
+ };
47
+ }
48
+ /* </replacement> */
49
+
50
+ /*<replacement>*/
51
+ var Duplex;
52
+ /*</replacement>*/
53
+
54
+ Writable.WritableState = WritableState;
55
+
56
+ /*<replacement>*/
57
+ var internalUtil = {
58
+ deprecate: require('util-deprecate')
59
+ };
60
+ /*</replacement>*/
61
+
62
+ /*<replacement>*/
63
+ var Stream = require('./internal/streams/stream');
64
+ /*</replacement>*/
65
+
66
+ var Buffer = require('buffer').Buffer;
67
+ var OurUint8Array = (typeof global !== 'undefined' ? global : typeof window !== 'undefined' ? window : typeof self !== 'undefined' ? self : {}).Uint8Array || function () {};
68
+ function _uint8ArrayToBuffer(chunk) {
69
+ return Buffer.from(chunk);
70
+ }
71
+ function _isUint8Array(obj) {
72
+ return Buffer.isBuffer(obj) || obj instanceof OurUint8Array;
73
+ }
74
+ var destroyImpl = require('./internal/streams/destroy');
75
+ var _require = require('./internal/streams/state'),
76
+ getHighWaterMark = _require.getHighWaterMark;
77
+ var _require$codes = require('../errors').codes,
78
+ ERR_INVALID_ARG_TYPE = _require$codes.ERR_INVALID_ARG_TYPE,
79
+ ERR_METHOD_NOT_IMPLEMENTED = _require$codes.ERR_METHOD_NOT_IMPLEMENTED,
80
+ ERR_MULTIPLE_CALLBACK = _require$codes.ERR_MULTIPLE_CALLBACK,
81
+ ERR_STREAM_CANNOT_PIPE = _require$codes.ERR_STREAM_CANNOT_PIPE,
82
+ ERR_STREAM_DESTROYED = _require$codes.ERR_STREAM_DESTROYED,
83
+ ERR_STREAM_NULL_VALUES = _require$codes.ERR_STREAM_NULL_VALUES,
84
+ ERR_STREAM_WRITE_AFTER_END = _require$codes.ERR_STREAM_WRITE_AFTER_END,
85
+ ERR_UNKNOWN_ENCODING = _require$codes.ERR_UNKNOWN_ENCODING;
86
+ var errorOrDestroy = destroyImpl.errorOrDestroy;
87
+ require('inherits')(Writable, Stream);
88
+ function nop() {}
89
+ function WritableState(options, stream, isDuplex) {
90
+ Duplex = Duplex || require('./_stream_duplex');
91
+ options = options || {};
92
+
93
+ // Duplex streams are both readable and writable, but share
94
+ // the same options object.
95
+ // However, some cases require setting options to different
96
+ // values for the readable and the writable sides of the duplex stream,
97
+ // e.g. options.readableObjectMode vs. options.writableObjectMode, etc.
98
+ if (typeof isDuplex !== 'boolean') isDuplex = stream instanceof Duplex;
99
+
100
+ // object stream flag to indicate whether or not this stream
101
+ // contains buffers or objects.
102
+ this.objectMode = !!options.objectMode;
103
+ if (isDuplex) this.objectMode = this.objectMode || !!options.writableObjectMode;
104
+
105
+ // the point at which write() starts returning false
106
+ // Note: 0 is a valid value, means that we always return false if
107
+ // the entire buffer is not flushed immediately on write()
108
+ this.highWaterMark = getHighWaterMark(this, options, 'writableHighWaterMark', isDuplex);
109
+
110
+ // if _final has been called
111
+ this.finalCalled = false;
112
+
113
+ // drain event flag.
114
+ this.needDrain = false;
115
+ // at the start of calling end()
116
+ this.ending = false;
117
+ // when end() has been called, and returned
118
+ this.ended = false;
119
+ // when 'finish' is emitted
120
+ this.finished = false;
121
+
122
+ // has it been destroyed
123
+ this.destroyed = false;
124
+
125
+ // should we decode strings into buffers before passing to _write?
126
+ // this is here so that some node-core streams can optimize string
127
+ // handling at a lower level.
128
+ var noDecode = options.decodeStrings === false;
129
+ this.decodeStrings = !noDecode;
130
+
131
+ // Crypto is kind of old and crusty. Historically, its default string
132
+ // encoding is 'binary' so we have to make this configurable.
133
+ // Everything else in the universe uses 'utf8', though.
134
+ this.defaultEncoding = options.defaultEncoding || 'utf8';
135
+
136
+ // not an actual buffer we keep track of, but a measurement
137
+ // of how much we're waiting to get pushed to some underlying
138
+ // socket or file.
139
+ this.length = 0;
140
+
141
+ // a flag to see when we're in the middle of a write.
142
+ this.writing = false;
143
+
144
+ // when true all writes will be buffered until .uncork() call
145
+ this.corked = 0;
146
+
147
+ // a flag to be able to tell if the onwrite cb is called immediately,
148
+ // or on a later tick. We set this to true at first, because any
149
+ // actions that shouldn't happen until "later" should generally also
150
+ // not happen before the first write call.
151
+ this.sync = true;
152
+
153
+ // a flag to know if we're processing previously buffered items, which
154
+ // may call the _write() callback in the same tick, so that we don't
155
+ // end up in an overlapped onwrite situation.
156
+ this.bufferProcessing = false;
157
+
158
+ // the callback that's passed to _write(chunk,cb)
159
+ this.onwrite = function (er) {
160
+ onwrite(stream, er);
161
+ };
162
+
163
+ // the callback that the user supplies to write(chunk,encoding,cb)
164
+ this.writecb = null;
165
+
166
+ // the amount that is being written when _write is called.
167
+ this.writelen = 0;
168
+ this.bufferedRequest = null;
169
+ this.lastBufferedRequest = null;
170
+
171
+ // number of pending user-supplied write callbacks
172
+ // this must be 0 before 'finish' can be emitted
173
+ this.pendingcb = 0;
174
+
175
+ // emit prefinish if the only thing we're waiting for is _write cbs
176
+ // This is relevant for synchronous Transform streams
177
+ this.prefinished = false;
178
+
179
+ // True if the error was already emitted and should not be thrown again
180
+ this.errorEmitted = false;
181
+
182
+ // Should close be emitted on destroy. Defaults to true.
183
+ this.emitClose = options.emitClose !== false;
184
+
185
+ // Should .destroy() be called after 'finish' (and potentially 'end')
186
+ this.autoDestroy = !!options.autoDestroy;
187
+
188
+ // count buffered requests
189
+ this.bufferedRequestCount = 0;
190
+
191
+ // allocate the first CorkedRequest, there is always
192
+ // one allocated and free to use, and we maintain at most two
193
+ this.corkedRequestsFree = new CorkedRequest(this);
194
+ }
195
+ WritableState.prototype.getBuffer = function getBuffer() {
196
+ var current = this.bufferedRequest;
197
+ var out = [];
198
+ while (current) {
199
+ out.push(current);
200
+ current = current.next;
201
+ }
202
+ return out;
203
+ };
204
+ (function () {
205
+ try {
206
+ Object.defineProperty(WritableState.prototype, 'buffer', {
207
+ get: internalUtil.deprecate(function writableStateBufferGetter() {
208
+ return this.getBuffer();
209
+ }, '_writableState.buffer is deprecated. Use _writableState.getBuffer ' + 'instead.', 'DEP0003')
210
+ });
211
+ } catch (_) {}
212
+ })();
213
+
214
+ // Test _writableState for inheritance to account for Duplex streams,
215
+ // whose prototype chain only points to Readable.
216
+ var realHasInstance;
217
+ if (typeof Symbol === 'function' && Symbol.hasInstance && typeof Function.prototype[Symbol.hasInstance] === 'function') {
218
+ realHasInstance = Function.prototype[Symbol.hasInstance];
219
+ Object.defineProperty(Writable, Symbol.hasInstance, {
220
+ value: function value(object) {
221
+ if (realHasInstance.call(this, object)) return true;
222
+ if (this !== Writable) return false;
223
+ return object && object._writableState instanceof WritableState;
224
+ }
225
+ });
226
+ } else {
227
+ realHasInstance = function realHasInstance(object) {
228
+ return object instanceof this;
229
+ };
230
+ }
231
+ function Writable(options) {
232
+ Duplex = Duplex || require('./_stream_duplex');
233
+
234
+ // Writable ctor is applied to Duplexes, too.
235
+ // `realHasInstance` is necessary because using plain `instanceof`
236
+ // would return false, as no `_writableState` property is attached.
237
+
238
+ // Trying to use the custom `instanceof` for Writable here will also break the
239
+ // Node.js LazyTransform implementation, which has a non-trivial getter for
240
+ // `_writableState` that would lead to infinite recursion.
241
+
242
+ // Checking for a Stream.Duplex instance is faster here instead of inside
243
+ // the WritableState constructor, at least with V8 6.5
244
+ var isDuplex = this instanceof Duplex;
245
+ if (!isDuplex && !realHasInstance.call(Writable, this)) return new Writable(options);
246
+ this._writableState = new WritableState(options, this, isDuplex);
247
+
248
+ // legacy.
249
+ this.writable = true;
250
+ if (options) {
251
+ if (typeof options.write === 'function') this._write = options.write;
252
+ if (typeof options.writev === 'function') this._writev = options.writev;
253
+ if (typeof options.destroy === 'function') this._destroy = options.destroy;
254
+ if (typeof options.final === 'function') this._final = options.final;
255
+ }
256
+ Stream.call(this);
257
+ }
258
+
259
+ // Otherwise people can pipe Writable streams, which is just wrong.
260
+ Writable.prototype.pipe = function () {
261
+ errorOrDestroy(this, new ERR_STREAM_CANNOT_PIPE());
262
+ };
263
+ function writeAfterEnd(stream, cb) {
264
+ var er = new ERR_STREAM_WRITE_AFTER_END();
265
+ // TODO: defer error events consistently everywhere, not just the cb
266
+ errorOrDestroy(stream, er);
267
+ process.nextTick(cb, er);
268
+ }
269
+
270
+ // Checks that a user-supplied chunk is valid, especially for the particular
271
+ // mode the stream is in. Currently this means that `null` is never accepted
272
+ // and undefined/non-string values are only allowed in object mode.
273
+ function validChunk(stream, state, chunk, cb) {
274
+ var er;
275
+ if (chunk === null) {
276
+ er = new ERR_STREAM_NULL_VALUES();
277
+ } else if (typeof chunk !== 'string' && !state.objectMode) {
278
+ er = new ERR_INVALID_ARG_TYPE('chunk', ['string', 'Buffer'], chunk);
279
+ }
280
+ if (er) {
281
+ errorOrDestroy(stream, er);
282
+ process.nextTick(cb, er);
283
+ return false;
284
+ }
285
+ return true;
286
+ }
287
+ Writable.prototype.write = function (chunk, encoding, cb) {
288
+ var state = this._writableState;
289
+ var ret = false;
290
+ var isBuf = !state.objectMode && _isUint8Array(chunk);
291
+ if (isBuf && !Buffer.isBuffer(chunk)) {
292
+ chunk = _uint8ArrayToBuffer(chunk);
293
+ }
294
+ if (typeof encoding === 'function') {
295
+ cb = encoding;
296
+ encoding = null;
297
+ }
298
+ if (isBuf) encoding = 'buffer';else if (!encoding) encoding = state.defaultEncoding;
299
+ if (typeof cb !== 'function') cb = nop;
300
+ if (state.ending) writeAfterEnd(this, cb);else if (isBuf || validChunk(this, state, chunk, cb)) {
301
+ state.pendingcb++;
302
+ ret = writeOrBuffer(this, state, isBuf, chunk, encoding, cb);
303
+ }
304
+ return ret;
305
+ };
306
+ Writable.prototype.cork = function () {
307
+ this._writableState.corked++;
308
+ };
309
+ Writable.prototype.uncork = function () {
310
+ var state = this._writableState;
311
+ if (state.corked) {
312
+ state.corked--;
313
+ if (!state.writing && !state.corked && !state.bufferProcessing && state.bufferedRequest) clearBuffer(this, state);
314
+ }
315
+ };
316
+ Writable.prototype.setDefaultEncoding = function setDefaultEncoding(encoding) {
317
+ // node::ParseEncoding() requires lower case.
318
+ if (typeof encoding === 'string') encoding = encoding.toLowerCase();
319
+ if (!(['hex', 'utf8', 'utf-8', 'ascii', 'binary', 'base64', 'ucs2', 'ucs-2', 'utf16le', 'utf-16le', 'raw'].indexOf((encoding + '').toLowerCase()) > -1)) throw new ERR_UNKNOWN_ENCODING(encoding);
320
+ this._writableState.defaultEncoding = encoding;
321
+ return this;
322
+ };
323
+ Object.defineProperty(Writable.prototype, 'writableBuffer', {
324
+ // making it explicit this property is not enumerable
325
+ // because otherwise some prototype manipulation in
326
+ // userland will fail
327
+ enumerable: false,
328
+ get: function get() {
329
+ return this._writableState && this._writableState.getBuffer();
330
+ }
331
+ });
332
+ function decodeChunk(state, chunk, encoding) {
333
+ if (!state.objectMode && state.decodeStrings !== false && typeof chunk === 'string') {
334
+ chunk = Buffer.from(chunk, encoding);
335
+ }
336
+ return chunk;
337
+ }
338
+ Object.defineProperty(Writable.prototype, 'writableHighWaterMark', {
339
+ // making it explicit this property is not enumerable
340
+ // because otherwise some prototype manipulation in
341
+ // userland will fail
342
+ enumerable: false,
343
+ get: function get() {
344
+ return this._writableState.highWaterMark;
345
+ }
346
+ });
347
+
348
+ // if we're already writing something, then just put this
349
+ // in the queue, and wait our turn. Otherwise, call _write
350
+ // If we return false, then we need a drain event, so set that flag.
351
+ function writeOrBuffer(stream, state, isBuf, chunk, encoding, cb) {
352
+ if (!isBuf) {
353
+ var newChunk = decodeChunk(state, chunk, encoding);
354
+ if (chunk !== newChunk) {
355
+ isBuf = true;
356
+ encoding = 'buffer';
357
+ chunk = newChunk;
358
+ }
359
+ }
360
+ var len = state.objectMode ? 1 : chunk.length;
361
+ state.length += len;
362
+ var ret = state.length < state.highWaterMark;
363
+ // we must ensure that previous needDrain will not be reset to false.
364
+ if (!ret) state.needDrain = true;
365
+ if (state.writing || state.corked) {
366
+ var last = state.lastBufferedRequest;
367
+ state.lastBufferedRequest = {
368
+ chunk: chunk,
369
+ encoding: encoding,
370
+ isBuf: isBuf,
371
+ callback: cb,
372
+ next: null
373
+ };
374
+ if (last) {
375
+ last.next = state.lastBufferedRequest;
376
+ } else {
377
+ state.bufferedRequest = state.lastBufferedRequest;
378
+ }
379
+ state.bufferedRequestCount += 1;
380
+ } else {
381
+ doWrite(stream, state, false, len, chunk, encoding, cb);
382
+ }
383
+ return ret;
384
+ }
385
+ function doWrite(stream, state, writev, len, chunk, encoding, cb) {
386
+ state.writelen = len;
387
+ state.writecb = cb;
388
+ state.writing = true;
389
+ state.sync = true;
390
+ if (state.destroyed) state.onwrite(new ERR_STREAM_DESTROYED('write'));else if (writev) stream._writev(chunk, state.onwrite);else stream._write(chunk, encoding, state.onwrite);
391
+ state.sync = false;
392
+ }
393
+ function onwriteError(stream, state, sync, er, cb) {
394
+ --state.pendingcb;
395
+ if (sync) {
396
+ // defer the callback if we are being called synchronously
397
+ // to avoid piling up things on the stack
398
+ process.nextTick(cb, er);
399
+ // this can emit finish, and it will always happen
400
+ // after error
401
+ process.nextTick(finishMaybe, stream, state);
402
+ stream._writableState.errorEmitted = true;
403
+ errorOrDestroy(stream, er);
404
+ } else {
405
+ // the caller expect this to happen before if
406
+ // it is async
407
+ cb(er);
408
+ stream._writableState.errorEmitted = true;
409
+ errorOrDestroy(stream, er);
410
+ // this can emit finish, but finish must
411
+ // always follow error
412
+ finishMaybe(stream, state);
413
+ }
414
+ }
415
+ function onwriteStateUpdate(state) {
416
+ state.writing = false;
417
+ state.writecb = null;
418
+ state.length -= state.writelen;
419
+ state.writelen = 0;
420
+ }
421
+ function onwrite(stream, er) {
422
+ var state = stream._writableState;
423
+ var sync = state.sync;
424
+ var cb = state.writecb;
425
+ if (typeof cb !== 'function') throw new ERR_MULTIPLE_CALLBACK();
426
+ onwriteStateUpdate(state);
427
+ if (er) onwriteError(stream, state, sync, er, cb);else {
428
+ // Check if we're actually ready to finish, but don't emit yet
429
+ var finished = needFinish(state) || stream.destroyed;
430
+ if (!finished && !state.corked && !state.bufferProcessing && state.bufferedRequest) {
431
+ clearBuffer(stream, state);
432
+ }
433
+ if (sync) {
434
+ process.nextTick(afterWrite, stream, state, finished, cb);
435
+ } else {
436
+ afterWrite(stream, state, finished, cb);
437
+ }
438
+ }
439
+ }
440
+ function afterWrite(stream, state, finished, cb) {
441
+ if (!finished) onwriteDrain(stream, state);
442
+ state.pendingcb--;
443
+ cb();
444
+ finishMaybe(stream, state);
445
+ }
446
+
447
+ // Must force callback to be called on nextTick, so that we don't
448
+ // emit 'drain' before the write() consumer gets the 'false' return
449
+ // value, and has a chance to attach a 'drain' listener.
450
+ function onwriteDrain(stream, state) {
451
+ if (state.length === 0 && state.needDrain) {
452
+ state.needDrain = false;
453
+ stream.emit('drain');
454
+ }
455
+ }
456
+
457
+ // if there's something in the buffer waiting, then process it
458
+ function clearBuffer(stream, state) {
459
+ state.bufferProcessing = true;
460
+ var entry = state.bufferedRequest;
461
+ if (stream._writev && entry && entry.next) {
462
+ // Fast case, write everything using _writev()
463
+ var l = state.bufferedRequestCount;
464
+ var buffer = new Array(l);
465
+ var holder = state.corkedRequestsFree;
466
+ holder.entry = entry;
467
+ var count = 0;
468
+ var allBuffers = true;
469
+ while (entry) {
470
+ buffer[count] = entry;
471
+ if (!entry.isBuf) allBuffers = false;
472
+ entry = entry.next;
473
+ count += 1;
474
+ }
475
+ buffer.allBuffers = allBuffers;
476
+ doWrite(stream, state, true, state.length, buffer, '', holder.finish);
477
+
478
+ // doWrite is almost always async, defer these to save a bit of time
479
+ // as the hot path ends with doWrite
480
+ state.pendingcb++;
481
+ state.lastBufferedRequest = null;
482
+ if (holder.next) {
483
+ state.corkedRequestsFree = holder.next;
484
+ holder.next = null;
485
+ } else {
486
+ state.corkedRequestsFree = new CorkedRequest(state);
487
+ }
488
+ state.bufferedRequestCount = 0;
489
+ } else {
490
+ // Slow case, write chunks one-by-one
491
+ while (entry) {
492
+ var chunk = entry.chunk;
493
+ var encoding = entry.encoding;
494
+ var cb = entry.callback;
495
+ var len = state.objectMode ? 1 : chunk.length;
496
+ doWrite(stream, state, false, len, chunk, encoding, cb);
497
+ entry = entry.next;
498
+ state.bufferedRequestCount--;
499
+ // if we didn't call the onwrite immediately, then
500
+ // it means that we need to wait until it does.
501
+ // also, that means that the chunk and cb are currently
502
+ // being processed, so move the buffer counter past them.
503
+ if (state.writing) {
504
+ break;
505
+ }
506
+ }
507
+ if (entry === null) state.lastBufferedRequest = null;
508
+ }
509
+ state.bufferedRequest = entry;
510
+ state.bufferProcessing = false;
511
+ }
512
+ Writable.prototype._write = function (chunk, encoding, cb) {
513
+ cb(new ERR_METHOD_NOT_IMPLEMENTED('_write()'));
514
+ };
515
+ Writable.prototype._writev = null;
516
+ Writable.prototype.end = function (chunk, encoding, cb) {
517
+ var state = this._writableState;
518
+ if (typeof chunk === 'function') {
519
+ cb = chunk;
520
+ chunk = null;
521
+ encoding = null;
522
+ } else if (typeof encoding === 'function') {
523
+ cb = encoding;
524
+ encoding = null;
525
+ }
526
+ if (chunk !== null && chunk !== undefined) this.write(chunk, encoding);
527
+
528
+ // .end() fully uncorks
529
+ if (state.corked) {
530
+ state.corked = 1;
531
+ this.uncork();
532
+ }
533
+
534
+ // ignore unnecessary end() calls.
535
+ if (!state.ending) endWritable(this, state, cb);
536
+ return this;
537
+ };
538
+ Object.defineProperty(Writable.prototype, 'writableLength', {
539
+ // making it explicit this property is not enumerable
540
+ // because otherwise some prototype manipulation in
541
+ // userland will fail
542
+ enumerable: false,
543
+ get: function get() {
544
+ return this._writableState.length;
545
+ }
546
+ });
547
+ function needFinish(state) {
548
+ return state.ending && state.length === 0 && state.bufferedRequest === null && !state.finished && !state.writing;
549
+ }
550
+ function callFinal(stream, state) {
551
+ stream._final(function (err) {
552
+ state.pendingcb--;
553
+ if (err) {
554
+ errorOrDestroy(stream, err);
555
+ }
556
+ state.prefinished = true;
557
+ stream.emit('prefinish');
558
+ finishMaybe(stream, state);
559
+ });
560
+ }
561
+ function prefinish(stream, state) {
562
+ if (!state.prefinished && !state.finalCalled) {
563
+ if (typeof stream._final === 'function' && !state.destroyed) {
564
+ state.pendingcb++;
565
+ state.finalCalled = true;
566
+ process.nextTick(callFinal, stream, state);
567
+ } else {
568
+ state.prefinished = true;
569
+ stream.emit('prefinish');
570
+ }
571
+ }
572
+ }
573
+ function finishMaybe(stream, state) {
574
+ var need = needFinish(state);
575
+ if (need) {
576
+ prefinish(stream, state);
577
+ if (state.pendingcb === 0) {
578
+ state.finished = true;
579
+ stream.emit('finish');
580
+ if (state.autoDestroy) {
581
+ // In case of duplex streams we need a way to detect
582
+ // if the readable side is ready for autoDestroy as well
583
+ var rState = stream._readableState;
584
+ if (!rState || rState.autoDestroy && rState.endEmitted) {
585
+ stream.destroy();
586
+ }
587
+ }
588
+ }
589
+ }
590
+ return need;
591
+ }
592
+ function endWritable(stream, state, cb) {
593
+ state.ending = true;
594
+ finishMaybe(stream, state);
595
+ if (cb) {
596
+ if (state.finished) process.nextTick(cb);else stream.once('finish', cb);
597
+ }
598
+ state.ended = true;
599
+ stream.writable = false;
600
+ }
601
+ function onCorkedFinish(corkReq, state, err) {
602
+ var entry = corkReq.entry;
603
+ corkReq.entry = null;
604
+ while (entry) {
605
+ var cb = entry.callback;
606
+ state.pendingcb--;
607
+ cb(err);
608
+ entry = entry.next;
609
+ }
610
+
611
+ // reuse the free corkReq.
612
+ state.corkedRequestsFree.next = corkReq;
613
+ }
614
+ Object.defineProperty(Writable.prototype, 'destroyed', {
615
+ // making it explicit this property is not enumerable
616
+ // because otherwise some prototype manipulation in
617
+ // userland will fail
618
+ enumerable: false,
619
+ get: function get() {
620
+ if (this._writableState === undefined) {
621
+ return false;
622
+ }
623
+ return this._writableState.destroyed;
624
+ },
625
+ set: function set(value) {
626
+ // we ignore the value if the stream
627
+ // has not been initialized yet
628
+ if (!this._writableState) {
629
+ return;
630
+ }
631
+
632
+ // backward compatibility, the user is explicitly
633
+ // managing destroyed
634
+ this._writableState.destroyed = value;
635
+ }
636
+ });
637
+ Writable.prototype.destroy = destroyImpl.destroy;
638
+ Writable.prototype._undestroy = destroyImpl.undestroy;
639
+ Writable.prototype._destroy = function (err, cb) {
640
+ cb(err);
641
+ };
node_modules/stream-browserify/node_modules/readable-stream/lib/internal/streams/async_iterator.js ADDED
@@ -0,0 +1,180 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 'use strict';
2
+
3
+ var _Object$setPrototypeO;
4
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
6
+ function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
7
+ var finished = require('./end-of-stream');
8
+ var kLastResolve = Symbol('lastResolve');
9
+ var kLastReject = Symbol('lastReject');
10
+ var kError = Symbol('error');
11
+ var kEnded = Symbol('ended');
12
+ var kLastPromise = Symbol('lastPromise');
13
+ var kHandlePromise = Symbol('handlePromise');
14
+ var kStream = Symbol('stream');
15
+ function createIterResult(value, done) {
16
+ return {
17
+ value: value,
18
+ done: done
19
+ };
20
+ }
21
+ function readAndResolve(iter) {
22
+ var resolve = iter[kLastResolve];
23
+ if (resolve !== null) {
24
+ var data = iter[kStream].read();
25
+ // we defer if data is null
26
+ // we can be expecting either 'end' or
27
+ // 'error'
28
+ if (data !== null) {
29
+ iter[kLastPromise] = null;
30
+ iter[kLastResolve] = null;
31
+ iter[kLastReject] = null;
32
+ resolve(createIterResult(data, false));
33
+ }
34
+ }
35
+ }
36
+ function onReadable(iter) {
37
+ // we wait for the next tick, because it might
38
+ // emit an error with process.nextTick
39
+ process.nextTick(readAndResolve, iter);
40
+ }
41
+ function wrapForNext(lastPromise, iter) {
42
+ return function (resolve, reject) {
43
+ lastPromise.then(function () {
44
+ if (iter[kEnded]) {
45
+ resolve(createIterResult(undefined, true));
46
+ return;
47
+ }
48
+ iter[kHandlePromise](resolve, reject);
49
+ }, reject);
50
+ };
51
+ }
52
+ var AsyncIteratorPrototype = Object.getPrototypeOf(function () {});
53
+ var ReadableStreamAsyncIteratorPrototype = Object.setPrototypeOf((_Object$setPrototypeO = {
54
+ get stream() {
55
+ return this[kStream];
56
+ },
57
+ next: function next() {
58
+ var _this = this;
59
+ // if we have detected an error in the meanwhile
60
+ // reject straight away
61
+ var error = this[kError];
62
+ if (error !== null) {
63
+ return Promise.reject(error);
64
+ }
65
+ if (this[kEnded]) {
66
+ return Promise.resolve(createIterResult(undefined, true));
67
+ }
68
+ if (this[kStream].destroyed) {
69
+ // We need to defer via nextTick because if .destroy(err) is
70
+ // called, the error will be emitted via nextTick, and
71
+ // we cannot guarantee that there is no error lingering around
72
+ // waiting to be emitted.
73
+ return new Promise(function (resolve, reject) {
74
+ process.nextTick(function () {
75
+ if (_this[kError]) {
76
+ reject(_this[kError]);
77
+ } else {
78
+ resolve(createIterResult(undefined, true));
79
+ }
80
+ });
81
+ });
82
+ }
83
+
84
+ // if we have multiple next() calls
85
+ // we will wait for the previous Promise to finish
86
+ // this logic is optimized to support for await loops,
87
+ // where next() is only called once at a time
88
+ var lastPromise = this[kLastPromise];
89
+ var promise;
90
+ if (lastPromise) {
91
+ promise = new Promise(wrapForNext(lastPromise, this));
92
+ } else {
93
+ // fast path needed to support multiple this.push()
94
+ // without triggering the next() queue
95
+ var data = this[kStream].read();
96
+ if (data !== null) {
97
+ return Promise.resolve(createIterResult(data, false));
98
+ }
99
+ promise = new Promise(this[kHandlePromise]);
100
+ }
101
+ this[kLastPromise] = promise;
102
+ return promise;
103
+ }
104
+ }, _defineProperty(_Object$setPrototypeO, Symbol.asyncIterator, function () {
105
+ return this;
106
+ }), _defineProperty(_Object$setPrototypeO, "return", function _return() {
107
+ var _this2 = this;
108
+ // destroy(err, cb) is a private API
109
+ // we can guarantee we have that here, because we control the
110
+ // Readable class this is attached to
111
+ return new Promise(function (resolve, reject) {
112
+ _this2[kStream].destroy(null, function (err) {
113
+ if (err) {
114
+ reject(err);
115
+ return;
116
+ }
117
+ resolve(createIterResult(undefined, true));
118
+ });
119
+ });
120
+ }), _Object$setPrototypeO), AsyncIteratorPrototype);
121
+ var createReadableStreamAsyncIterator = function createReadableStreamAsyncIterator(stream) {
122
+ var _Object$create;
123
+ var iterator = Object.create(ReadableStreamAsyncIteratorPrototype, (_Object$create = {}, _defineProperty(_Object$create, kStream, {
124
+ value: stream,
125
+ writable: true
126
+ }), _defineProperty(_Object$create, kLastResolve, {
127
+ value: null,
128
+ writable: true
129
+ }), _defineProperty(_Object$create, kLastReject, {
130
+ value: null,
131
+ writable: true
132
+ }), _defineProperty(_Object$create, kError, {
133
+ value: null,
134
+ writable: true
135
+ }), _defineProperty(_Object$create, kEnded, {
136
+ value: stream._readableState.endEmitted,
137
+ writable: true
138
+ }), _defineProperty(_Object$create, kHandlePromise, {
139
+ value: function value(resolve, reject) {
140
+ var data = iterator[kStream].read();
141
+ if (data) {
142
+ iterator[kLastPromise] = null;
143
+ iterator[kLastResolve] = null;
144
+ iterator[kLastReject] = null;
145
+ resolve(createIterResult(data, false));
146
+ } else {
147
+ iterator[kLastResolve] = resolve;
148
+ iterator[kLastReject] = reject;
149
+ }
150
+ },
151
+ writable: true
152
+ }), _Object$create));
153
+ iterator[kLastPromise] = null;
154
+ finished(stream, function (err) {
155
+ if (err && err.code !== 'ERR_STREAM_PREMATURE_CLOSE') {
156
+ var reject = iterator[kLastReject];
157
+ // reject if we are waiting for data in the Promise
158
+ // returned by next() and store the error
159
+ if (reject !== null) {
160
+ iterator[kLastPromise] = null;
161
+ iterator[kLastResolve] = null;
162
+ iterator[kLastReject] = null;
163
+ reject(err);
164
+ }
165
+ iterator[kError] = err;
166
+ return;
167
+ }
168
+ var resolve = iterator[kLastResolve];
169
+ if (resolve !== null) {
170
+ iterator[kLastPromise] = null;
171
+ iterator[kLastResolve] = null;
172
+ iterator[kLastReject] = null;
173
+ resolve(createIterResult(undefined, true));
174
+ }
175
+ iterator[kEnded] = true;
176
+ });
177
+ stream.on('readable', onReadable.bind(null, iterator));
178
+ return iterator;
179
+ };
180
+ module.exports = createReadableStreamAsyncIterator;
node_modules/stream-browserify/node_modules/readable-stream/lib/internal/streams/buffer_list.js ADDED
@@ -0,0 +1,183 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 'use strict';
2
+
3
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
4
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
5
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
7
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
8
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
9
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
10
+ function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
11
+ var _require = require('buffer'),
12
+ Buffer = _require.Buffer;
13
+ var _require2 = require('util'),
14
+ inspect = _require2.inspect;
15
+ var custom = inspect && inspect.custom || 'inspect';
16
+ function copyBuffer(src, target, offset) {
17
+ Buffer.prototype.copy.call(src, target, offset);
18
+ }
19
+ module.exports = /*#__PURE__*/function () {
20
+ function BufferList() {
21
+ _classCallCheck(this, BufferList);
22
+ this.head = null;
23
+ this.tail = null;
24
+ this.length = 0;
25
+ }
26
+ _createClass(BufferList, [{
27
+ key: "push",
28
+ value: function push(v) {
29
+ var entry = {
30
+ data: v,
31
+ next: null
32
+ };
33
+ if (this.length > 0) this.tail.next = entry;else this.head = entry;
34
+ this.tail = entry;
35
+ ++this.length;
36
+ }
37
+ }, {
38
+ key: "unshift",
39
+ value: function unshift(v) {
40
+ var entry = {
41
+ data: v,
42
+ next: this.head
43
+ };
44
+ if (this.length === 0) this.tail = entry;
45
+ this.head = entry;
46
+ ++this.length;
47
+ }
48
+ }, {
49
+ key: "shift",
50
+ value: function shift() {
51
+ if (this.length === 0) return;
52
+ var ret = this.head.data;
53
+ if (this.length === 1) this.head = this.tail = null;else this.head = this.head.next;
54
+ --this.length;
55
+ return ret;
56
+ }
57
+ }, {
58
+ key: "clear",
59
+ value: function clear() {
60
+ this.head = this.tail = null;
61
+ this.length = 0;
62
+ }
63
+ }, {
64
+ key: "join",
65
+ value: function join(s) {
66
+ if (this.length === 0) return '';
67
+ var p = this.head;
68
+ var ret = '' + p.data;
69
+ while (p = p.next) ret += s + p.data;
70
+ return ret;
71
+ }
72
+ }, {
73
+ key: "concat",
74
+ value: function concat(n) {
75
+ if (this.length === 0) return Buffer.alloc(0);
76
+ var ret = Buffer.allocUnsafe(n >>> 0);
77
+ var p = this.head;
78
+ var i = 0;
79
+ while (p) {
80
+ copyBuffer(p.data, ret, i);
81
+ i += p.data.length;
82
+ p = p.next;
83
+ }
84
+ return ret;
85
+ }
86
+
87
+ // Consumes a specified amount of bytes or characters from the buffered data.
88
+ }, {
89
+ key: "consume",
90
+ value: function consume(n, hasStrings) {
91
+ var ret;
92
+ if (n < this.head.data.length) {
93
+ // `slice` is the same for buffers and strings.
94
+ ret = this.head.data.slice(0, n);
95
+ this.head.data = this.head.data.slice(n);
96
+ } else if (n === this.head.data.length) {
97
+ // First chunk is a perfect match.
98
+ ret = this.shift();
99
+ } else {
100
+ // Result spans more than one buffer.
101
+ ret = hasStrings ? this._getString(n) : this._getBuffer(n);
102
+ }
103
+ return ret;
104
+ }
105
+ }, {
106
+ key: "first",
107
+ value: function first() {
108
+ return this.head.data;
109
+ }
110
+
111
+ // Consumes a specified amount of characters from the buffered data.
112
+ }, {
113
+ key: "_getString",
114
+ value: function _getString(n) {
115
+ var p = this.head;
116
+ var c = 1;
117
+ var ret = p.data;
118
+ n -= ret.length;
119
+ while (p = p.next) {
120
+ var str = p.data;
121
+ var nb = n > str.length ? str.length : n;
122
+ if (nb === str.length) ret += str;else ret += str.slice(0, n);
123
+ n -= nb;
124
+ if (n === 0) {
125
+ if (nb === str.length) {
126
+ ++c;
127
+ if (p.next) this.head = p.next;else this.head = this.tail = null;
128
+ } else {
129
+ this.head = p;
130
+ p.data = str.slice(nb);
131
+ }
132
+ break;
133
+ }
134
+ ++c;
135
+ }
136
+ this.length -= c;
137
+ return ret;
138
+ }
139
+
140
+ // Consumes a specified amount of bytes from the buffered data.
141
+ }, {
142
+ key: "_getBuffer",
143
+ value: function _getBuffer(n) {
144
+ var ret = Buffer.allocUnsafe(n);
145
+ var p = this.head;
146
+ var c = 1;
147
+ p.data.copy(ret);
148
+ n -= p.data.length;
149
+ while (p = p.next) {
150
+ var buf = p.data;
151
+ var nb = n > buf.length ? buf.length : n;
152
+ buf.copy(ret, ret.length - n, 0, nb);
153
+ n -= nb;
154
+ if (n === 0) {
155
+ if (nb === buf.length) {
156
+ ++c;
157
+ if (p.next) this.head = p.next;else this.head = this.tail = null;
158
+ } else {
159
+ this.head = p;
160
+ p.data = buf.slice(nb);
161
+ }
162
+ break;
163
+ }
164
+ ++c;
165
+ }
166
+ this.length -= c;
167
+ return ret;
168
+ }
169
+
170
+ // Make sure the linked list only shows the minimal necessary information.
171
+ }, {
172
+ key: custom,
173
+ value: function value(_, options) {
174
+ return inspect(this, _objectSpread(_objectSpread({}, options), {}, {
175
+ // Only inspect one level.
176
+ depth: 0,
177
+ // It should not recurse.
178
+ customInspect: false
179
+ }));
180
+ }
181
+ }]);
182
+ return BufferList;
183
+ }();
node_modules/stream-browserify/node_modules/readable-stream/lib/internal/streams/destroy.js ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 'use strict';
2
+
3
+ // undocumented cb() API, needed for core, not for public API
4
+ function destroy(err, cb) {
5
+ var _this = this;
6
+ var readableDestroyed = this._readableState && this._readableState.destroyed;
7
+ var writableDestroyed = this._writableState && this._writableState.destroyed;
8
+ if (readableDestroyed || writableDestroyed) {
9
+ if (cb) {
10
+ cb(err);
11
+ } else if (err) {
12
+ if (!this._writableState) {
13
+ process.nextTick(emitErrorNT, this, err);
14
+ } else if (!this._writableState.errorEmitted) {
15
+ this._writableState.errorEmitted = true;
16
+ process.nextTick(emitErrorNT, this, err);
17
+ }
18
+ }
19
+ return this;
20
+ }
21
+
22
+ // we set destroyed to true before firing error callbacks in order
23
+ // to make it re-entrance safe in case destroy() is called within callbacks
24
+
25
+ if (this._readableState) {
26
+ this._readableState.destroyed = true;
27
+ }
28
+
29
+ // if this is a duplex stream mark the writable part as destroyed as well
30
+ if (this._writableState) {
31
+ this._writableState.destroyed = true;
32
+ }
33
+ this._destroy(err || null, function (err) {
34
+ if (!cb && err) {
35
+ if (!_this._writableState) {
36
+ process.nextTick(emitErrorAndCloseNT, _this, err);
37
+ } else if (!_this._writableState.errorEmitted) {
38
+ _this._writableState.errorEmitted = true;
39
+ process.nextTick(emitErrorAndCloseNT, _this, err);
40
+ } else {
41
+ process.nextTick(emitCloseNT, _this);
42
+ }
43
+ } else if (cb) {
44
+ process.nextTick(emitCloseNT, _this);
45
+ cb(err);
46
+ } else {
47
+ process.nextTick(emitCloseNT, _this);
48
+ }
49
+ });
50
+ return this;
51
+ }
52
+ function emitErrorAndCloseNT(self, err) {
53
+ emitErrorNT(self, err);
54
+ emitCloseNT(self);
55
+ }
56
+ function emitCloseNT(self) {
57
+ if (self._writableState && !self._writableState.emitClose) return;
58
+ if (self._readableState && !self._readableState.emitClose) return;
59
+ self.emit('close');
60
+ }
61
+ function undestroy() {
62
+ if (this._readableState) {
63
+ this._readableState.destroyed = false;
64
+ this._readableState.reading = false;
65
+ this._readableState.ended = false;
66
+ this._readableState.endEmitted = false;
67
+ }
68
+ if (this._writableState) {
69
+ this._writableState.destroyed = false;
70
+ this._writableState.ended = false;
71
+ this._writableState.ending = false;
72
+ this._writableState.finalCalled = false;
73
+ this._writableState.prefinished = false;
74
+ this._writableState.finished = false;
75
+ this._writableState.errorEmitted = false;
76
+ }
77
+ }
78
+ function emitErrorNT(self, err) {
79
+ self.emit('error', err);
80
+ }
81
+ function errorOrDestroy(stream, err) {
82
+ // We have tests that rely on errors being emitted
83
+ // in the same tick, so changing this is semver major.
84
+ // For now when you opt-in to autoDestroy we allow
85
+ // the error to be emitted nextTick. In a future
86
+ // semver major update we should change the default to this.
87
+
88
+ var rState = stream._readableState;
89
+ var wState = stream._writableState;
90
+ if (rState && rState.autoDestroy || wState && wState.autoDestroy) stream.destroy(err);else stream.emit('error', err);
91
+ }
92
+ module.exports = {
93
+ destroy: destroy,
94
+ undestroy: undestroy,
95
+ errorOrDestroy: errorOrDestroy
96
+ };
node_modules/stream-browserify/node_modules/readable-stream/lib/internal/streams/end-of-stream.js ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Ported from https://github.com/mafintosh/end-of-stream with
2
+ // permission from the author, Mathias Buus (@mafintosh).
3
+
4
+ 'use strict';
5
+
6
+ var ERR_STREAM_PREMATURE_CLOSE = require('../../../errors').codes.ERR_STREAM_PREMATURE_CLOSE;
7
+ function once(callback) {
8
+ var called = false;
9
+ return function () {
10
+ if (called) return;
11
+ called = true;
12
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
13
+ args[_key] = arguments[_key];
14
+ }
15
+ callback.apply(this, args);
16
+ };
17
+ }
18
+ function noop() {}
19
+ function isRequest(stream) {
20
+ return stream.setHeader && typeof stream.abort === 'function';
21
+ }
22
+ function eos(stream, opts, callback) {
23
+ if (typeof opts === 'function') return eos(stream, null, opts);
24
+ if (!opts) opts = {};
25
+ callback = once(callback || noop);
26
+ var readable = opts.readable || opts.readable !== false && stream.readable;
27
+ var writable = opts.writable || opts.writable !== false && stream.writable;
28
+ var onlegacyfinish = function onlegacyfinish() {
29
+ if (!stream.writable) onfinish();
30
+ };
31
+ var writableEnded = stream._writableState && stream._writableState.finished;
32
+ var onfinish = function onfinish() {
33
+ writable = false;
34
+ writableEnded = true;
35
+ if (!readable) callback.call(stream);
36
+ };
37
+ var readableEnded = stream._readableState && stream._readableState.endEmitted;
38
+ var onend = function onend() {
39
+ readable = false;
40
+ readableEnded = true;
41
+ if (!writable) callback.call(stream);
42
+ };
43
+ var onerror = function onerror(err) {
44
+ callback.call(stream, err);
45
+ };
46
+ var onclose = function onclose() {
47
+ var err;
48
+ if (readable && !readableEnded) {
49
+ if (!stream._readableState || !stream._readableState.ended) err = new ERR_STREAM_PREMATURE_CLOSE();
50
+ return callback.call(stream, err);
51
+ }
52
+ if (writable && !writableEnded) {
53
+ if (!stream._writableState || !stream._writableState.ended) err = new ERR_STREAM_PREMATURE_CLOSE();
54
+ return callback.call(stream, err);
55
+ }
56
+ };
57
+ var onrequest = function onrequest() {
58
+ stream.req.on('finish', onfinish);
59
+ };
60
+ if (isRequest(stream)) {
61
+ stream.on('complete', onfinish);
62
+ stream.on('abort', onclose);
63
+ if (stream.req) onrequest();else stream.on('request', onrequest);
64
+ } else if (writable && !stream._writableState) {
65
+ // legacy streams
66
+ stream.on('end', onlegacyfinish);
67
+ stream.on('close', onlegacyfinish);
68
+ }
69
+ stream.on('end', onend);
70
+ stream.on('finish', onfinish);
71
+ if (opts.error !== false) stream.on('error', onerror);
72
+ stream.on('close', onclose);
73
+ return function () {
74
+ stream.removeListener('complete', onfinish);
75
+ stream.removeListener('abort', onclose);
76
+ stream.removeListener('request', onrequest);
77
+ if (stream.req) stream.req.removeListener('finish', onfinish);
78
+ stream.removeListener('end', onlegacyfinish);
79
+ stream.removeListener('close', onlegacyfinish);
80
+ stream.removeListener('finish', onfinish);
81
+ stream.removeListener('end', onend);
82
+ stream.removeListener('error', onerror);
83
+ stream.removeListener('close', onclose);
84
+ };
85
+ }
86
+ module.exports = eos;
node_modules/stream-browserify/node_modules/readable-stream/lib/internal/streams/from-browser.js ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ module.exports = function () {
2
+ throw new Error('Readable.from is not available in the browser')
3
+ };
node_modules/stream-browserify/node_modules/readable-stream/lib/internal/streams/from.js ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 'use strict';
2
+
3
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
4
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
5
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
6
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
7
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
8
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
9
+ function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
10
+ var ERR_INVALID_ARG_TYPE = require('../../../errors').codes.ERR_INVALID_ARG_TYPE;
11
+ function from(Readable, iterable, opts) {
12
+ var iterator;
13
+ if (iterable && typeof iterable.next === 'function') {
14
+ iterator = iterable;
15
+ } else if (iterable && iterable[Symbol.asyncIterator]) iterator = iterable[Symbol.asyncIterator]();else if (iterable && iterable[Symbol.iterator]) iterator = iterable[Symbol.iterator]();else throw new ERR_INVALID_ARG_TYPE('iterable', ['Iterable'], iterable);
16
+ var readable = new Readable(_objectSpread({
17
+ objectMode: true
18
+ }, opts));
19
+ // Reading boolean to protect against _read
20
+ // being called before last iteration completion.
21
+ var reading = false;
22
+ readable._read = function () {
23
+ if (!reading) {
24
+ reading = true;
25
+ next();
26
+ }
27
+ };
28
+ function next() {
29
+ return _next2.apply(this, arguments);
30
+ }
31
+ function _next2() {
32
+ _next2 = _asyncToGenerator(function* () {
33
+ try {
34
+ var _yield$iterator$next = yield iterator.next(),
35
+ value = _yield$iterator$next.value,
36
+ done = _yield$iterator$next.done;
37
+ if (done) {
38
+ readable.push(null);
39
+ } else if (readable.push(yield value)) {
40
+ next();
41
+ } else {
42
+ reading = false;
43
+ }
44
+ } catch (err) {
45
+ readable.destroy(err);
46
+ }
47
+ });
48
+ return _next2.apply(this, arguments);
49
+ }
50
+ return readable;
51
+ }
52
+ module.exports = from;
node_modules/stream-browserify/node_modules/readable-stream/lib/internal/streams/pipeline.js ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Ported from https://github.com/mafintosh/pump with
2
+ // permission from the author, Mathias Buus (@mafintosh).
3
+
4
+ 'use strict';
5
+
6
+ var eos;
7
+ function once(callback) {
8
+ var called = false;
9
+ return function () {
10
+ if (called) return;
11
+ called = true;
12
+ callback.apply(void 0, arguments);
13
+ };
14
+ }
15
+ var _require$codes = require('../../../errors').codes,
16
+ ERR_MISSING_ARGS = _require$codes.ERR_MISSING_ARGS,
17
+ ERR_STREAM_DESTROYED = _require$codes.ERR_STREAM_DESTROYED;
18
+ function noop(err) {
19
+ // Rethrow the error if it exists to avoid swallowing it
20
+ if (err) throw err;
21
+ }
22
+ function isRequest(stream) {
23
+ return stream.setHeader && typeof stream.abort === 'function';
24
+ }
25
+ function destroyer(stream, reading, writing, callback) {
26
+ callback = once(callback);
27
+ var closed = false;
28
+ stream.on('close', function () {
29
+ closed = true;
30
+ });
31
+ if (eos === undefined) eos = require('./end-of-stream');
32
+ eos(stream, {
33
+ readable: reading,
34
+ writable: writing
35
+ }, function (err) {
36
+ if (err) return callback(err);
37
+ closed = true;
38
+ callback();
39
+ });
40
+ var destroyed = false;
41
+ return function (err) {
42
+ if (closed) return;
43
+ if (destroyed) return;
44
+ destroyed = true;
45
+
46
+ // request.destroy just do .end - .abort is what we want
47
+ if (isRequest(stream)) return stream.abort();
48
+ if (typeof stream.destroy === 'function') return stream.destroy();
49
+ callback(err || new ERR_STREAM_DESTROYED('pipe'));
50
+ };
51
+ }
52
+ function call(fn) {
53
+ fn();
54
+ }
55
+ function pipe(from, to) {
56
+ return from.pipe(to);
57
+ }
58
+ function popCallback(streams) {
59
+ if (!streams.length) return noop;
60
+ if (typeof streams[streams.length - 1] !== 'function') return noop;
61
+ return streams.pop();
62
+ }
63
+ function pipeline() {
64
+ for (var _len = arguments.length, streams = new Array(_len), _key = 0; _key < _len; _key++) {
65
+ streams[_key] = arguments[_key];
66
+ }
67
+ var callback = popCallback(streams);
68
+ if (Array.isArray(streams[0])) streams = streams[0];
69
+ if (streams.length < 2) {
70
+ throw new ERR_MISSING_ARGS('streams');
71
+ }
72
+ var error;
73
+ var destroys = streams.map(function (stream, i) {
74
+ var reading = i < streams.length - 1;
75
+ var writing = i > 0;
76
+ return destroyer(stream, reading, writing, function (err) {
77
+ if (!error) error = err;
78
+ if (err) destroys.forEach(call);
79
+ if (reading) return;
80
+ destroys.forEach(call);
81
+ callback(error);
82
+ });
83
+ });
84
+ return streams.reduce(pipe);
85
+ }
86
+ module.exports = pipeline;
node_modules/stream-browserify/node_modules/readable-stream/lib/internal/streams/state.js ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 'use strict';
2
+
3
+ var ERR_INVALID_OPT_VALUE = require('../../../errors').codes.ERR_INVALID_OPT_VALUE;
4
+ function highWaterMarkFrom(options, isDuplex, duplexKey) {
5
+ return options.highWaterMark != null ? options.highWaterMark : isDuplex ? options[duplexKey] : null;
6
+ }
7
+ function getHighWaterMark(state, options, duplexKey, isDuplex) {
8
+ var hwm = highWaterMarkFrom(options, isDuplex, duplexKey);
9
+ if (hwm != null) {
10
+ if (!(isFinite(hwm) && Math.floor(hwm) === hwm) || hwm < 0) {
11
+ var name = isDuplex ? duplexKey : 'highWaterMark';
12
+ throw new ERR_INVALID_OPT_VALUE(name, hwm);
13
+ }
14
+ return Math.floor(hwm);
15
+ }
16
+
17
+ // Default value
18
+ return state.objectMode ? 16 : 16 * 1024;
19
+ }
20
+ module.exports = {
21
+ getHighWaterMark: getHighWaterMark
22
+ };
node_modules/stream-browserify/node_modules/readable-stream/lib/internal/streams/stream-browser.js ADDED
@@ -0,0 +1 @@
 
 
1
+ module.exports = require('events').EventEmitter;
node_modules/stream-browserify/node_modules/readable-stream/lib/internal/streams/stream.js ADDED
@@ -0,0 +1 @@
 
 
1
+ module.exports = require('stream');
node_modules/stream-browserify/node_modules/readable-stream/package.json ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "readable-stream",
3
+ "version": "3.6.2",
4
+ "description": "Streams3, a user-land copy of the stream library from Node.js",
5
+ "main": "readable.js",
6
+ "engines": {
7
+ "node": ">= 6"
8
+ },
9
+ "dependencies": {
10
+ "inherits": "^2.0.3",
11
+ "string_decoder": "^1.1.1",
12
+ "util-deprecate": "^1.0.1"
13
+ },
14
+ "devDependencies": {
15
+ "@babel/cli": "^7.2.0",
16
+ "@babel/core": "^7.2.0",
17
+ "@babel/polyfill": "^7.0.0",
18
+ "@babel/preset-env": "^7.2.0",
19
+ "airtap": "0.0.9",
20
+ "assert": "^1.4.0",
21
+ "bl": "^2.0.0",
22
+ "deep-strict-equal": "^0.2.0",
23
+ "events.once": "^2.0.2",
24
+ "glob": "^7.1.2",
25
+ "gunzip-maybe": "^1.4.1",
26
+ "hyperquest": "^2.1.3",
27
+ "lolex": "^2.6.0",
28
+ "nyc": "^11.0.0",
29
+ "pump": "^3.0.0",
30
+ "rimraf": "^2.6.2",
31
+ "tap": "^12.0.0",
32
+ "tape": "^4.9.0",
33
+ "tar-fs": "^1.16.2",
34
+ "util-promisify": "^2.1.0"
35
+ },
36
+ "scripts": {
37
+ "test": "tap -J --no-esm test/parallel/*.js test/ours/*.js",
38
+ "ci": "TAP=1 tap --no-esm test/parallel/*.js test/ours/*.js | tee test.tap",
39
+ "test-browsers": "airtap --sauce-connect --loopback airtap.local -- test/browser.js",
40
+ "test-browser-local": "airtap --open --local -- test/browser.js",
41
+ "cover": "nyc npm test",
42
+ "report": "nyc report --reporter=lcov",
43
+ "update-browser-errors": "babel -o errors-browser.js errors.js"
44
+ },
45
+ "repository": {
46
+ "type": "git",
47
+ "url": "git://github.com/nodejs/readable-stream"
48
+ },
49
+ "keywords": [
50
+ "readable",
51
+ "stream",
52
+ "pipe"
53
+ ],
54
+ "browser": {
55
+ "util": false,
56
+ "worker_threads": false,
57
+ "./errors": "./errors-browser.js",
58
+ "./readable.js": "./readable-browser.js",
59
+ "./lib/internal/streams/from.js": "./lib/internal/streams/from-browser.js",
60
+ "./lib/internal/streams/stream.js": "./lib/internal/streams/stream-browser.js"
61
+ },
62
+ "nyc": {
63
+ "include": [
64
+ "lib/**.js"
65
+ ]
66
+ },
67
+ "license": "MIT"
68
+ }
node_modules/stream-browserify/node_modules/readable-stream/readable-browser.js ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ exports = module.exports = require('./lib/_stream_readable.js');
2
+ exports.Stream = exports;
3
+ exports.Readable = exports;
4
+ exports.Writable = require('./lib/_stream_writable.js');
5
+ exports.Duplex = require('./lib/_stream_duplex.js');
6
+ exports.Transform = require('./lib/_stream_transform.js');
7
+ exports.PassThrough = require('./lib/_stream_passthrough.js');
8
+ exports.finished = require('./lib/internal/streams/end-of-stream.js');
9
+ exports.pipeline = require('./lib/internal/streams/pipeline.js');
node_modules/stream-browserify/node_modules/readable-stream/readable.js ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var Stream = require('stream');
2
+ if (process.env.READABLE_STREAM === 'disable' && Stream) {
3
+ module.exports = Stream.Readable;
4
+ Object.assign(module.exports, Stream);
5
+ module.exports.Stream = Stream;
6
+ } else {
7
+ exports = module.exports = require('./lib/_stream_readable.js');
8
+ exports.Stream = Stream || exports;
9
+ exports.Readable = exports;
10
+ exports.Writable = require('./lib/_stream_writable.js');
11
+ exports.Duplex = require('./lib/_stream_duplex.js');
12
+ exports.Transform = require('./lib/_stream_transform.js');
13
+ exports.PassThrough = require('./lib/_stream_passthrough.js');
14
+ exports.finished = require('./lib/internal/streams/end-of-stream.js');
15
+ exports.pipeline = require('./lib/internal/streams/pipeline.js');
16
+ }
node_modules/stream-browserify/package.json ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "stream-browserify",
3
+ "version": "3.0.0",
4
+ "description": "the stream module from node core for browsers",
5
+ "main": "index.js",
6
+ "dependencies": {
7
+ "inherits": "~2.0.4",
8
+ "readable-stream": "^3.5.0"
9
+ },
10
+ "devDependencies": {
11
+ "airtap": "^1.0.2",
12
+ "safe-buffer": "^5.1.2",
13
+ "tape": "^4.13.0",
14
+ "through": "^2.3.8"
15
+ },
16
+ "scripts": {
17
+ "test": "node test",
18
+ "test:browsers": "airtap -- test/index.js"
19
+ },
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git://github.com/browserify/stream-browserify.git"
23
+ },
24
+ "homepage": "https://github.com/browserify/stream-browserify",
25
+ "keywords": [
26
+ "stream",
27
+ "browser",
28
+ "browserify"
29
+ ],
30
+ "author": {
31
+ "name": "James Halliday",
32
+ "email": "mail@substack.net",
33
+ "url": "http://substack.net"
34
+ },
35
+ "license": "MIT",
36
+ "testling": {
37
+ "files": "test/*.js",
38
+ "browsers": [
39
+ "ie/8..latest",
40
+ "firefox/3.5",
41
+ "firefox/10",
42
+ "firefox/nightly",
43
+ "chrome/10",
44
+ "chrome/latest",
45
+ "chrome/canary",
46
+ "opera/12..latest",
47
+ "opera/next",
48
+ "safari/5.1..latest",
49
+ "ipad/6.0..latest",
50
+ "iphone/6.0..latest",
51
+ "android-browser/4.2..latest"
52
+ ]
53
+ }
54
+ }
node_modules/stream-browserify/readme.markdown ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # stream-browserify
2
+
3
+ the stream module from node core, for browsers!
4
+
5
+ This module uses [`readable-stream`](https://github.com/nodejs/readable-stream), with additions for compatibility with npm packages that use old Node.js stream APIs.
6
+
7
+ [![build status](https://secure.travis-ci.org/browserify/stream-browserify.svg?branch=master)](http://travis-ci.org/browserify/stream-browserify)
8
+
9
+ ## Install
10
+
11
+ You usually do not have to install `stream-browserify` yourself! If your code runs in Node.js, `stream` is built in, or `readable-stream` can be used. If your code runs in the browser, bundlers like [browserify](https://github.com/browserify/browserify) also include the `stream-browserify` module.
12
+
13
+ But if none of those apply, with [npm](https://npmjs.org) do:
14
+
15
+ ```bash
16
+ npm install stream-browserify
17
+ ```
18
+
19
+ ## API
20
+
21
+ Consult the node core
22
+ [documentation on streams](http://nodejs.org/docs/latest/api/stream.html).
23
+
24
+ ## Browser Support
25
+
26
+ Cross-browser testing generously provided by [Sauce Labs](https://saucelabs.com).
27
+
28
+ [![Sauce Test Status](https://saucelabs.com/browser-matrix/stream-browserify.svg)](https://saucelabs.com/u/stream-browserify)
29
+
30
+ ## License
31
+
32
+ [MIT](./LICENSE)
node_modules/stream-browserify/security.md ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ # Security Policy
2
+
3
+ ## Supported Versions
4
+ Only the latest major version is supported at any given time.
5
+
6
+ ## Reporting a Vulnerability
7
+
8
+ To report a security vulnerability, please use the
9
+ [Tidelift security contact](https://tidelift.com/security).
10
+ Tidelift will coordinate the fix and disclosure.
node_modules/stream-browserify/test/buf.js ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var path = require('path');
2
+ var test = require('tape');
3
+ var Buffer = require('safe-buffer').Buffer;
4
+
5
+ var Writable = require('..').Writable;
6
+ var inherits = require('inherits');
7
+
8
+ inherits(TestWritable, Writable);
9
+
10
+ function TestWritable(opt) {
11
+ if (!(this instanceof TestWritable))
12
+ return new TestWritable(opt);
13
+ Writable.call(this, opt);
14
+ this._written = [];
15
+ }
16
+
17
+ TestWritable.prototype._write = function(chunk, encoding, cb) {
18
+ this._written.push(chunk);
19
+ cb();
20
+ };
21
+
22
+ var buf = Buffer.from([ 88 ]);
23
+
24
+ test('.writable writing ArrayBuffer', function(t) {
25
+ var writable = new TestWritable();
26
+
27
+ writable.write(buf);
28
+ writable.end();
29
+
30
+ t.equal(writable._written.length, 1);
31
+ t.equal(writable._written[0].toString(), 'X')
32
+ t.end()
33
+ });
node_modules/stream-browserify/test/index.js ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ require('./buf');
2
+ require('./pipeline');
node_modules/stream-browserify/test/pipeline.js ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var test = require('tape');
2
+ var pipeline = require('..').pipeline;
3
+ var stream = require('..');
4
+ var Buffer = require('safe-buffer').Buffer;
5
+
6
+ test('supports pipeline', function(t) {
7
+ t.plan(4);
8
+ var readable = new stream.Readable({
9
+ read: function () {
10
+ this.push(Buffer.from('chunk', 'ascii'));
11
+ }
12
+ });
13
+ var transform1 = new stream.Transform({
14
+ transform: function (chunk, enc, cb) {
15
+ cb(new Error('fail'));
16
+ }
17
+ });
18
+ var transform2 = new stream.PassThrough();
19
+ transform2.on('close', function () {
20
+ t.pass('transform2.close called');
21
+ });
22
+ var writable = new stream.Writable({
23
+ write: function (chunk, enc, cb) { cb(); }
24
+ });
25
+ writable.on('close', function () {
26
+ t.pass('writable.close called');
27
+ });
28
+
29
+ pipeline(
30
+ readable,
31
+ transform1,
32
+ transform2,
33
+ writable,
34
+ function(err) {
35
+ t.ok(err);
36
+ t.equal(err.message, 'fail');
37
+ });
38
+ });
node_modules/stream-browserify/test/use-stream.js ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ // browserify plugin to swap out the `stream` builtin node shim with the stream-browserify version in this repo.
2
+ module.exports = function (b) {
3
+ b._mdeps.options.modules.stream = require.resolve('../index.js');
4
+ };
node_modules/stream-http/LICENSE ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ The MIT License
2
+
3
+ Copyright (c) 2015 John Hiesey
4
+
5
+ Permission is hereby granted, free of charge,
6
+ to any person obtaining a copy of this software and
7
+ associated documentation files (the "Software"), to
8
+ deal in the Software without restriction, including
9
+ without limitation the rights to use, copy, modify,
10
+ merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom
12
+ the Software is furnished to do so,
13
+ subject to the following conditions:
14
+
15
+ The above copyright notice and this permission notice
16
+ shall be included in all copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
22
+ ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
node_modules/stream-http/README.md ADDED
@@ -0,0 +1,134 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # stream-http [![Build Status](https://travis-ci.org/jhiesey/stream-http.svg?branch=master)](https://travis-ci.org/jhiesey/stream-http)
2
+
3
+ [![Sauce Test Status](https://app.saucelabs.com/browser-matrix/stream-http.svg)](https://app.saucelabs.com/u/stream-http)
4
+
5
+ This module is an implementation of Node's native `http` module for the browser.
6
+ It tries to match Node's API and behavior as closely as possible, but some features
7
+ aren't available, since browsers don't give nearly as much control over requests.
8
+
9
+ This is heavily inspired by, and intended to replace, [http-browserify](https://github.com/substack/http-browserify).
10
+
11
+ ## What does it do?
12
+
13
+ In accordance with its name, `stream-http` tries to provide data to its caller before
14
+ the request has completed whenever possible.
15
+
16
+ Backpressure, allowing the browser to only pull data from the server as fast as it is
17
+ consumed, is supported in:
18
+ * Chrome >= 58 (using `fetch` and `WritableStream`)
19
+
20
+ The following browsers support true streaming, where only a small amount of the request
21
+ has to be held in memory at once:
22
+ * Chrome >= 43 (using the `fetch` API)
23
+ * Firefox >= 9 (using `moz-chunked-arraybuffer` responseType with xhr)
24
+
25
+ All other supported browsers support pseudo-streaming, where the data is available before
26
+ the request finishes, but the entire response must be held in memory. This works for both
27
+ text and binary data.
28
+
29
+ ### IE note:
30
+ As of version 3.0.0, IE10 and below are no longer supported. IE11 support will remain for
31
+ now.
32
+
33
+ ## How do you use it?
34
+
35
+ The intent is to have the same API as the client part of the
36
+ [Node HTTP module](https://nodejs.org/api/http.html). The interfaces are the same wherever
37
+ practical, although limitations in browsers make an exact clone of the Node API impossible.
38
+
39
+ This module implements `http.request`, `http.get`, and most of `http.ClientRequest`
40
+ and `http.IncomingMessage` in addition to `http.METHODS` and `http.STATUS_CODES`. See the
41
+ Node docs for how these work.
42
+
43
+ ### Extra features compared to Node
44
+
45
+ * The `message.url` property provides access to the final URL after all redirects. This
46
+ is useful since the browser follows all redirects silently, unlike Node. It is available
47
+ in Chrome 37 and newer, Firefox 32 and newer, and Safari 9 and newer.
48
+
49
+ * The `options.withCredentials` boolean flag, used to indicate if the browser should send
50
+ cookies or authentication information with a CORS request. Default false.
51
+
52
+ This module has to make some tradeoffs to support binary data and/or streaming. Generally,
53
+ the module can make a fairly good decision about which underlying browser features to use,
54
+ but sometimes it helps to get a little input from the developer.
55
+
56
+ * The `options.mode` field passed into `http.request` or `http.get` can take on one of the
57
+ following values:
58
+ * 'default' (or any falsy value, including `undefined`): Try to provide partial data before
59
+ the request completes, but not at the cost of correctness for binary data or correctness of
60
+ the 'content-type' response header. This mode will also avoid slower code paths whenever
61
+ possible, which is particularly useful when making large requests in a browser like Safari
62
+ that has a weaker JavaScript engine.
63
+ * 'allow-wrong-content-type': Provides partial data in more cases than 'default', but
64
+ at the expense of causing the 'content-type' response header to be incorrectly reported
65
+ (as 'text/plain; charset=x-user-defined') in some browsers, notably Safari and Chrome 42
66
+ and older. Preserves binary data whenever possible. In some cases the implementation may
67
+ also be a bit slow. This was the default in versions of this module before 1.5.
68
+ * 'prefer-streaming': Provide data before the request completes even if binary data (anything
69
+ that isn't a single-byte ASCII or UTF8 character) will be corrupted. Of course, this option
70
+ is only safe for text data. May also cause the 'content-type' response header to be
71
+ incorrectly reported (as 'text/plain; charset=x-user-defined').
72
+ * 'disable-fetch': Force the use of plain XHR regardless of the browser declaring a fetch
73
+ capability. Preserves the correctness of binary data and the 'content-type' response header.
74
+ * 'prefer-fast': Deprecated; now a synonym for 'default', which has the same performance
75
+ characteristics as this mode did in versions before 1.5.
76
+
77
+ * `options.requestTimeout` allows setting a timeout in millisecionds for XHR and fetch (if
78
+ supported by the browser). This is a limit on how long the entire process takes from
79
+ beginning to end. Note that this is not the same as the node `setTimeout` functions,
80
+ which apply to pauses in data transfer over the underlying socket, or the node `timeout`
81
+ option, which applies to opening the connection.
82
+
83
+ ### Features missing compared to Node
84
+
85
+ * `http.Agent` is only a stub
86
+ * The 'socket', 'connect', 'upgrade', and 'continue' events on `http.ClientRequest`.
87
+ * Any operations, other than `request.setTimeout`, that operate directly on the underlying
88
+ socket.
89
+ * Any options that are disallowed for security reasons. This includes setting or getting
90
+ certain headers.
91
+ * `message.httpVersion`
92
+ * `message.rawHeaders` is modified by the browser, and may not quite match what is sent by
93
+ the server.
94
+ * `message.trailers` and `message.rawTrailers` will remain empty.
95
+ * Redirects are followed silently by the browser, so it isn't possible to access the 301/302
96
+ redirect pages.
97
+
98
+ ## Example
99
+
100
+ ``` js
101
+ http.get('/bundle.js', function (res) {
102
+ var div = document.getElementById('result');
103
+ div.innerHTML += 'GET /beep<br>';
104
+
105
+ res.on('data', function (buf) {
106
+ div.innerHTML += buf;
107
+ });
108
+
109
+ res.on('end', function () {
110
+ div.innerHTML += '<br>__END__';
111
+ });
112
+ })
113
+ ```
114
+
115
+ ## Running tests
116
+
117
+ There are two sets of tests: the tests that run in Node (found in `test/node`) and the tests
118
+ that run in the browser (found in `test/browser`). Normally the browser tests run on
119
+ [Sauce Labs](http://saucelabs.com/).
120
+
121
+ Running `npm test` will run both sets of tests, but in order for the Sauce Labs tests to run
122
+ you will need to sign up for an account (free for open source projects) and put the
123
+ credentials in a [`.airtaprc` file](https://github.com/airtap/airtap/blob/master/doc/airtaprc.md).
124
+ You will also need to run a [Sauce Connect Proxy](https://wiki.saucelabs.com/display/DOCS/Sauce+Connect+Proxy)
125
+ with the same credentials.
126
+
127
+ To run just the Node tests, run `npm run test-node`.
128
+
129
+ To run the browser tests locally, run `npm run test-browser-local` and point your browser to
130
+ the link shown in your terminal.
131
+
132
+ ## License
133
+
134
+ MIT. Copyright (C) John Hiesey and other contributors.
node_modules/stream-http/index.js ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var ClientRequest = require('./lib/request')
2
+ var response = require('./lib/response')
3
+ var extend = require('xtend')
4
+ var statusCodes = require('builtin-status-codes')
5
+ var url = require('url')
6
+
7
+ var http = exports
8
+
9
+ http.request = function (opts, cb) {
10
+ if (typeof opts === 'string')
11
+ opts = url.parse(opts)
12
+ else
13
+ opts = extend(opts)
14
+
15
+ // Normally, the page is loaded from http or https, so not specifying a protocol
16
+ // will result in a (valid) protocol-relative url. However, this won't work if
17
+ // the protocol is something else, like 'file:'
18
+ var defaultProtocol = global.location.protocol.search(/^https?:$/) === -1 ? 'http:' : ''
19
+
20
+ var protocol = opts.protocol || defaultProtocol
21
+ var host = opts.hostname || opts.host
22
+ var port = opts.port
23
+ var path = opts.path || '/'
24
+
25
+ // Necessary for IPv6 addresses
26
+ if (host && host.indexOf(':') !== -1)
27
+ host = '[' + host + ']'
28
+
29
+ // This may be a relative url. The browser should always be able to interpret it correctly.
30
+ opts.url = (host ? (protocol + '//' + host) : '') + (port ? ':' + port : '') + path
31
+ opts.method = (opts.method || 'GET').toUpperCase()
32
+ opts.headers = opts.headers || {}
33
+
34
+ // Also valid opts.auth, opts.mode
35
+
36
+ var req = new ClientRequest(opts)
37
+ if (cb)
38
+ req.on('response', cb)
39
+ return req
40
+ }
41
+
42
+ http.get = function get (opts, cb) {
43
+ var req = http.request(opts, cb)
44
+ req.end()
45
+ return req
46
+ }
47
+
48
+ http.ClientRequest = ClientRequest
49
+ http.IncomingMessage = response.IncomingMessage
50
+
51
+ http.Agent = function () {}
52
+ http.Agent.defaultMaxSockets = 4
53
+
54
+ http.globalAgent = new http.Agent()
55
+
56
+ http.STATUS_CODES = statusCodes
57
+
58
+ http.METHODS = [
59
+ 'CHECKOUT',
60
+ 'CONNECT',
61
+ 'COPY',
62
+ 'DELETE',
63
+ 'GET',
64
+ 'HEAD',
65
+ 'LOCK',
66
+ 'M-SEARCH',
67
+ 'MERGE',
68
+ 'MKACTIVITY',
69
+ 'MKCOL',
70
+ 'MOVE',
71
+ 'NOTIFY',
72
+ 'OPTIONS',
73
+ 'PATCH',
74
+ 'POST',
75
+ 'PROPFIND',
76
+ 'PROPPATCH',
77
+ 'PURGE',
78
+ 'PUT',
79
+ 'REPORT',
80
+ 'SEARCH',
81
+ 'SUBSCRIBE',
82
+ 'TRACE',
83
+ 'UNLOCK',
84
+ 'UNSUBSCRIBE'
85
+ ]
node_modules/stream-http/lib/capability.js ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ exports.fetch = isFunction(global.fetch) && isFunction(global.ReadableStream)
2
+
3
+ exports.writableStream = isFunction(global.WritableStream)
4
+
5
+ exports.abortController = isFunction(global.AbortController)
6
+
7
+ // The xhr request to example.com may violate some restrictive CSP configurations,
8
+ // so if we're running in a browser that supports `fetch`, avoid calling getXHR()
9
+ // and assume support for certain features below.
10
+ var xhr
11
+ function getXHR () {
12
+ // Cache the xhr value
13
+ if (xhr !== undefined) return xhr
14
+
15
+ if (global.XMLHttpRequest) {
16
+ xhr = new global.XMLHttpRequest()
17
+ // If XDomainRequest is available (ie only, where xhr might not work
18
+ // cross domain), use the page location. Otherwise use example.com
19
+ // Note: this doesn't actually make an http request.
20
+ try {
21
+ xhr.open('GET', global.XDomainRequest ? '/' : 'https://example.com')
22
+ } catch(e) {
23
+ xhr = null
24
+ }
25
+ } else {
26
+ // Service workers don't have XHR
27
+ xhr = null
28
+ }
29
+ return xhr
30
+ }
31
+
32
+ function checkTypeSupport (type) {
33
+ var xhr = getXHR()
34
+ if (!xhr) return false
35
+ try {
36
+ xhr.responseType = type
37
+ return xhr.responseType === type
38
+ } catch (e) {}
39
+ return false
40
+ }
41
+
42
+ // If fetch is supported, then arraybuffer will be supported too. Skip calling
43
+ // checkTypeSupport(), since that calls getXHR().
44
+ exports.arraybuffer = exports.fetch || checkTypeSupport('arraybuffer')
45
+
46
+ // These next two tests unavoidably show warnings in Chrome. Since fetch will always
47
+ // be used if it's available, just return false for these to avoid the warnings.
48
+ exports.msstream = !exports.fetch && checkTypeSupport('ms-stream')
49
+ exports.mozchunkedarraybuffer = !exports.fetch && checkTypeSupport('moz-chunked-arraybuffer')
50
+
51
+ // If fetch is supported, then overrideMimeType will be supported too. Skip calling
52
+ // getXHR().
53
+ exports.overrideMimeType = exports.fetch || (getXHR() ? isFunction(getXHR().overrideMimeType) : false)
54
+
55
+ function isFunction (value) {
56
+ return typeof value === 'function'
57
+ }
58
+
59
+ xhr = null // Help gc
node_modules/stream-http/lib/request.js ADDED
@@ -0,0 +1,352 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var capability = require('./capability')
2
+ var inherits = require('inherits')
3
+ var response = require('./response')
4
+ var stream = require('readable-stream')
5
+
6
+ var IncomingMessage = response.IncomingMessage
7
+ var rStates = response.readyStates
8
+
9
+ function decideMode (preferBinary, useFetch) {
10
+ if (capability.fetch && useFetch) {
11
+ return 'fetch'
12
+ } else if (capability.mozchunkedarraybuffer) {
13
+ return 'moz-chunked-arraybuffer'
14
+ } else if (capability.msstream) {
15
+ return 'ms-stream'
16
+ } else if (capability.arraybuffer && preferBinary) {
17
+ return 'arraybuffer'
18
+ } else {
19
+ return 'text'
20
+ }
21
+ }
22
+
23
+ var ClientRequest = module.exports = function (opts) {
24
+ var self = this
25
+ stream.Writable.call(self)
26
+
27
+ self._opts = opts
28
+ self._body = []
29
+ self._headers = {}
30
+ if (opts.auth)
31
+ self.setHeader('Authorization', 'Basic ' + Buffer.from(opts.auth).toString('base64'))
32
+ Object.keys(opts.headers).forEach(function (name) {
33
+ self.setHeader(name, opts.headers[name])
34
+ })
35
+
36
+ var preferBinary
37
+ var useFetch = true
38
+ if (opts.mode === 'disable-fetch' || ('requestTimeout' in opts && !capability.abortController)) {
39
+ // If the use of XHR should be preferred. Not typically needed.
40
+ useFetch = false
41
+ preferBinary = true
42
+ } else if (opts.mode === 'prefer-streaming') {
43
+ // If streaming is a high priority but binary compatibility and
44
+ // the accuracy of the 'content-type' header aren't
45
+ preferBinary = false
46
+ } else if (opts.mode === 'allow-wrong-content-type') {
47
+ // If streaming is more important than preserving the 'content-type' header
48
+ preferBinary = !capability.overrideMimeType
49
+ } else if (!opts.mode || opts.mode === 'default' || opts.mode === 'prefer-fast') {
50
+ // Use binary if text streaming may corrupt data or the content-type header, or for speed
51
+ preferBinary = true
52
+ } else {
53
+ throw new Error('Invalid value for opts.mode')
54
+ }
55
+ self._mode = decideMode(preferBinary, useFetch)
56
+ self._fetchTimer = null
57
+ self._socketTimeout = null
58
+ self._socketTimer = null
59
+
60
+ self.on('finish', function () {
61
+ self._onFinish()
62
+ })
63
+ }
64
+
65
+ inherits(ClientRequest, stream.Writable)
66
+
67
+ ClientRequest.prototype.setHeader = function (name, value) {
68
+ var self = this
69
+ var lowerName = name.toLowerCase()
70
+ // This check is not necessary, but it prevents warnings from browsers about setting unsafe
71
+ // headers. To be honest I'm not entirely sure hiding these warnings is a good thing, but
72
+ // http-browserify did it, so I will too.
73
+ if (unsafeHeaders.indexOf(lowerName) !== -1)
74
+ return
75
+
76
+ self._headers[lowerName] = {
77
+ name: name,
78
+ value: value
79
+ }
80
+ }
81
+
82
+ ClientRequest.prototype.getHeader = function (name) {
83
+ var header = this._headers[name.toLowerCase()]
84
+ if (header)
85
+ return header.value
86
+ return null
87
+ }
88
+
89
+ ClientRequest.prototype.removeHeader = function (name) {
90
+ var self = this
91
+ delete self._headers[name.toLowerCase()]
92
+ }
93
+
94
+ ClientRequest.prototype._onFinish = function () {
95
+ var self = this
96
+
97
+ if (self._destroyed)
98
+ return
99
+ var opts = self._opts
100
+
101
+ if ('timeout' in opts && opts.timeout !== 0) {
102
+ self.setTimeout(opts.timeout)
103
+ }
104
+
105
+ var headersObj = self._headers
106
+ var body = null
107
+ if (opts.method !== 'GET' && opts.method !== 'HEAD') {
108
+ body = new Blob(self._body, {
109
+ type: (headersObj['content-type'] || {}).value || ''
110
+ });
111
+ }
112
+
113
+ // create flattened list of headers
114
+ var headersList = []
115
+ Object.keys(headersObj).forEach(function (keyName) {
116
+ var name = headersObj[keyName].name
117
+ var value = headersObj[keyName].value
118
+ if (Array.isArray(value)) {
119
+ value.forEach(function (v) {
120
+ headersList.push([name, v])
121
+ })
122
+ } else {
123
+ headersList.push([name, value])
124
+ }
125
+ })
126
+
127
+ if (self._mode === 'fetch') {
128
+ var signal = null
129
+ if (capability.abortController) {
130
+ var controller = new AbortController()
131
+ signal = controller.signal
132
+ self._fetchAbortController = controller
133
+
134
+ if ('requestTimeout' in opts && opts.requestTimeout !== 0) {
135
+ self._fetchTimer = global.setTimeout(function () {
136
+ self.emit('requestTimeout')
137
+ if (self._fetchAbortController)
138
+ self._fetchAbortController.abort()
139
+ }, opts.requestTimeout)
140
+ }
141
+ }
142
+
143
+ global.fetch(self._opts.url, {
144
+ method: self._opts.method,
145
+ headers: headersList,
146
+ body: body || undefined,
147
+ mode: 'cors',
148
+ credentials: opts.withCredentials ? 'include' : 'same-origin',
149
+ signal: signal
150
+ }).then(function (response) {
151
+ self._fetchResponse = response
152
+ self._resetTimers(false)
153
+ self._connect()
154
+ }, function (reason) {
155
+ self._resetTimers(true)
156
+ if (!self._destroyed)
157
+ self.emit('error', reason)
158
+ })
159
+ } else {
160
+ var xhr = self._xhr = new global.XMLHttpRequest()
161
+ try {
162
+ xhr.open(self._opts.method, self._opts.url, true)
163
+ } catch (err) {
164
+ process.nextTick(function () {
165
+ self.emit('error', err)
166
+ })
167
+ return
168
+ }
169
+
170
+ // Can't set responseType on really old browsers
171
+ if ('responseType' in xhr)
172
+ xhr.responseType = self._mode
173
+
174
+ if ('withCredentials' in xhr)
175
+ xhr.withCredentials = !!opts.withCredentials
176
+
177
+ if (self._mode === 'text' && 'overrideMimeType' in xhr)
178
+ xhr.overrideMimeType('text/plain; charset=x-user-defined')
179
+
180
+ if ('requestTimeout' in opts) {
181
+ xhr.timeout = opts.requestTimeout
182
+ xhr.ontimeout = function () {
183
+ self.emit('requestTimeout')
184
+ }
185
+ }
186
+
187
+ headersList.forEach(function (header) {
188
+ xhr.setRequestHeader(header[0], header[1])
189
+ })
190
+
191
+ self._response = null
192
+ xhr.onreadystatechange = function () {
193
+ switch (xhr.readyState) {
194
+ case rStates.LOADING:
195
+ case rStates.DONE:
196
+ self._onXHRProgress()
197
+ break
198
+ }
199
+ }
200
+ // Necessary for streaming in Firefox, since xhr.response is ONLY defined
201
+ // in onprogress, not in onreadystatechange with xhr.readyState = 3
202
+ if (self._mode === 'moz-chunked-arraybuffer') {
203
+ xhr.onprogress = function () {
204
+ self._onXHRProgress()
205
+ }
206
+ }
207
+
208
+ xhr.onerror = function () {
209
+ if (self._destroyed)
210
+ return
211
+ self._resetTimers(true)
212
+ self.emit('error', new Error('XHR error'))
213
+ }
214
+
215
+ try {
216
+ xhr.send(body)
217
+ } catch (err) {
218
+ process.nextTick(function () {
219
+ self.emit('error', err)
220
+ })
221
+ return
222
+ }
223
+ }
224
+ }
225
+
226
+ /**
227
+ * Checks if xhr.status is readable and non-zero, indicating no error.
228
+ * Even though the spec says it should be available in readyState 3,
229
+ * accessing it throws an exception in IE8
230
+ */
231
+ function statusValid (xhr) {
232
+ try {
233
+ var status = xhr.status
234
+ return (status !== null && status !== 0)
235
+ } catch (e) {
236
+ return false
237
+ }
238
+ }
239
+
240
+ ClientRequest.prototype._onXHRProgress = function () {
241
+ var self = this
242
+
243
+ self._resetTimers(false)
244
+
245
+ if (!statusValid(self._xhr) || self._destroyed)
246
+ return
247
+
248
+ if (!self._response)
249
+ self._connect()
250
+
251
+ self._response._onXHRProgress(self._resetTimers.bind(self))
252
+ }
253
+
254
+ ClientRequest.prototype._connect = function () {
255
+ var self = this
256
+
257
+ if (self._destroyed)
258
+ return
259
+
260
+ self._response = new IncomingMessage(self._xhr, self._fetchResponse, self._mode, self._resetTimers.bind(self))
261
+ self._response.on('error', function(err) {
262
+ self.emit('error', err)
263
+ })
264
+
265
+ self.emit('response', self._response)
266
+ }
267
+
268
+ ClientRequest.prototype._write = function (chunk, encoding, cb) {
269
+ var self = this
270
+
271
+ self._body.push(chunk)
272
+ cb()
273
+ }
274
+
275
+ ClientRequest.prototype._resetTimers = function (done) {
276
+ var self = this
277
+
278
+ global.clearTimeout(self._socketTimer)
279
+ self._socketTimer = null
280
+
281
+ if (done) {
282
+ global.clearTimeout(self._fetchTimer)
283
+ self._fetchTimer = null
284
+ } else if (self._socketTimeout) {
285
+ self._socketTimer = global.setTimeout(function () {
286
+ self.emit('timeout')
287
+ }, self._socketTimeout)
288
+ }
289
+ }
290
+
291
+ ClientRequest.prototype.abort = ClientRequest.prototype.destroy = function (err) {
292
+ var self = this
293
+ self._destroyed = true
294
+ self._resetTimers(true)
295
+ if (self._response)
296
+ self._response._destroyed = true
297
+ if (self._xhr)
298
+ self._xhr.abort()
299
+ else if (self._fetchAbortController)
300
+ self._fetchAbortController.abort()
301
+
302
+ if (err)
303
+ self.emit('error', err)
304
+ }
305
+
306
+ ClientRequest.prototype.end = function (data, encoding, cb) {
307
+ var self = this
308
+ if (typeof data === 'function') {
309
+ cb = data
310
+ data = undefined
311
+ }
312
+
313
+ stream.Writable.prototype.end.call(self, data, encoding, cb)
314
+ }
315
+
316
+ ClientRequest.prototype.setTimeout = function (timeout, cb) {
317
+ var self = this
318
+
319
+ if (cb)
320
+ self.once('timeout', cb)
321
+
322
+ self._socketTimeout = timeout
323
+ self._resetTimers(false)
324
+ }
325
+
326
+ ClientRequest.prototype.flushHeaders = function () {}
327
+ ClientRequest.prototype.setNoDelay = function () {}
328
+ ClientRequest.prototype.setSocketKeepAlive = function () {}
329
+
330
+ // Taken from http://www.w3.org/TR/XMLHttpRequest/#the-setrequestheader%28%29-method
331
+ var unsafeHeaders = [
332
+ 'accept-charset',
333
+ 'accept-encoding',
334
+ 'access-control-request-headers',
335
+ 'access-control-request-method',
336
+ 'connection',
337
+ 'content-length',
338
+ 'cookie',
339
+ 'cookie2',
340
+ 'date',
341
+ 'dnt',
342
+ 'expect',
343
+ 'host',
344
+ 'keep-alive',
345
+ 'origin',
346
+ 'referer',
347
+ 'te',
348
+ 'trailer',
349
+ 'transfer-encoding',
350
+ 'upgrade',
351
+ 'via'
352
+ ]
node_modules/stream-http/lib/response.js ADDED
@@ -0,0 +1,211 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var capability = require('./capability')
2
+ var inherits = require('inherits')
3
+ var stream = require('readable-stream')
4
+
5
+ var rStates = exports.readyStates = {
6
+ UNSENT: 0,
7
+ OPENED: 1,
8
+ HEADERS_RECEIVED: 2,
9
+ LOADING: 3,
10
+ DONE: 4
11
+ }
12
+
13
+ var IncomingMessage = exports.IncomingMessage = function (xhr, response, mode, resetTimers) {
14
+ var self = this
15
+ stream.Readable.call(self)
16
+
17
+ self._mode = mode
18
+ self.headers = {}
19
+ self.rawHeaders = []
20
+ self.trailers = {}
21
+ self.rawTrailers = []
22
+
23
+ // Fake the 'close' event, but only once 'end' fires
24
+ self.on('end', function () {
25
+ // The nextTick is necessary to prevent the 'request' module from causing an infinite loop
26
+ process.nextTick(function () {
27
+ self.emit('close')
28
+ })
29
+ })
30
+
31
+ if (mode === 'fetch') {
32
+ self._fetchResponse = response
33
+
34
+ self.url = response.url
35
+ self.statusCode = response.status
36
+ self.statusMessage = response.statusText
37
+
38
+ response.headers.forEach(function (header, key){
39
+ self.headers[key.toLowerCase()] = header
40
+ self.rawHeaders.push(key, header)
41
+ })
42
+
43
+ if (capability.writableStream) {
44
+ var writable = new WritableStream({
45
+ write: function (chunk) {
46
+ resetTimers(false)
47
+ return new Promise(function (resolve, reject) {
48
+ if (self._destroyed) {
49
+ reject()
50
+ } else if(self.push(Buffer.from(chunk))) {
51
+ resolve()
52
+ } else {
53
+ self._resumeFetch = resolve
54
+ }
55
+ })
56
+ },
57
+ close: function () {
58
+ resetTimers(true)
59
+ if (!self._destroyed)
60
+ self.push(null)
61
+ },
62
+ abort: function (err) {
63
+ resetTimers(true)
64
+ if (!self._destroyed)
65
+ self.emit('error', err)
66
+ }
67
+ })
68
+
69
+ try {
70
+ response.body.pipeTo(writable).catch(function (err) {
71
+ resetTimers(true)
72
+ if (!self._destroyed)
73
+ self.emit('error', err)
74
+ })
75
+ return
76
+ } catch (e) {} // pipeTo method isn't defined. Can't find a better way to feature test this
77
+ }
78
+ // fallback for when writableStream or pipeTo aren't available
79
+ var reader = response.body.getReader()
80
+ function read () {
81
+ reader.read().then(function (result) {
82
+ if (self._destroyed)
83
+ return
84
+ resetTimers(result.done)
85
+ if (result.done) {
86
+ self.push(null)
87
+ return
88
+ }
89
+ self.push(Buffer.from(result.value))
90
+ read()
91
+ }).catch(function (err) {
92
+ resetTimers(true)
93
+ if (!self._destroyed)
94
+ self.emit('error', err)
95
+ })
96
+ }
97
+ read()
98
+ } else {
99
+ self._xhr = xhr
100
+ self._pos = 0
101
+
102
+ self.url = xhr.responseURL
103
+ self.statusCode = xhr.status
104
+ self.statusMessage = xhr.statusText
105
+ var headers = xhr.getAllResponseHeaders().split(/\r?\n/)
106
+ headers.forEach(function (header) {
107
+ var matches = header.match(/^([^:]+):\s*(.*)/)
108
+ if (matches) {
109
+ var key = matches[1].toLowerCase()
110
+ if (key === 'set-cookie') {
111
+ if (self.headers[key] === undefined) {
112
+ self.headers[key] = []
113
+ }
114
+ self.headers[key].push(matches[2])
115
+ } else if (self.headers[key] !== undefined) {
116
+ self.headers[key] += ', ' + matches[2]
117
+ } else {
118
+ self.headers[key] = matches[2]
119
+ }
120
+ self.rawHeaders.push(matches[1], matches[2])
121
+ }
122
+ })
123
+
124
+ self._charset = 'x-user-defined'
125
+ if (!capability.overrideMimeType) {
126
+ var mimeType = self.rawHeaders['mime-type']
127
+ if (mimeType) {
128
+ var charsetMatch = mimeType.match(/;\s*charset=([^;])(;|$)/)
129
+ if (charsetMatch) {
130
+ self._charset = charsetMatch[1].toLowerCase()
131
+ }
132
+ }
133
+ if (!self._charset)
134
+ self._charset = 'utf-8' // best guess
135
+ }
136
+ }
137
+ }
138
+
139
+ inherits(IncomingMessage, stream.Readable)
140
+
141
+ IncomingMessage.prototype._read = function () {
142
+ var self = this
143
+
144
+ var resolve = self._resumeFetch
145
+ if (resolve) {
146
+ self._resumeFetch = null
147
+ resolve()
148
+ }
149
+ }
150
+
151
+ IncomingMessage.prototype._onXHRProgress = function (resetTimers) {
152
+ var self = this
153
+
154
+ var xhr = self._xhr
155
+
156
+ var response = null
157
+ switch (self._mode) {
158
+ case 'text':
159
+ response = xhr.responseText
160
+ if (response.length > self._pos) {
161
+ var newData = response.substr(self._pos)
162
+ if (self._charset === 'x-user-defined') {
163
+ var buffer = Buffer.alloc(newData.length)
164
+ for (var i = 0; i < newData.length; i++)
165
+ buffer[i] = newData.charCodeAt(i) & 0xff
166
+
167
+ self.push(buffer)
168
+ } else {
169
+ self.push(newData, self._charset)
170
+ }
171
+ self._pos = response.length
172
+ }
173
+ break
174
+ case 'arraybuffer':
175
+ if (xhr.readyState !== rStates.DONE || !xhr.response)
176
+ break
177
+ response = xhr.response
178
+ self.push(Buffer.from(new Uint8Array(response)))
179
+ break
180
+ case 'moz-chunked-arraybuffer': // take whole
181
+ response = xhr.response
182
+ if (xhr.readyState !== rStates.LOADING || !response)
183
+ break
184
+ self.push(Buffer.from(new Uint8Array(response)))
185
+ break
186
+ case 'ms-stream':
187
+ response = xhr.response
188
+ if (xhr.readyState !== rStates.LOADING)
189
+ break
190
+ var reader = new global.MSStreamReader()
191
+ reader.onprogress = function () {
192
+ if (reader.result.byteLength > self._pos) {
193
+ self.push(Buffer.from(new Uint8Array(reader.result.slice(self._pos))))
194
+ self._pos = reader.result.byteLength
195
+ }
196
+ }
197
+ reader.onload = function () {
198
+ resetTimers(true)
199
+ self.push(null)
200
+ }
201
+ // reader.onerror = ??? // TODO: this
202
+ reader.readAsArrayBuffer(response)
203
+ break
204
+ }
205
+
206
+ // The ms-stream case handles end separately in reader.onload()
207
+ if (self._xhr.readyState === rStates.DONE && self._mode !== 'ms-stream') {
208
+ resetTimers(true)
209
+ self.push(null)
210
+ }
211
+ }
node_modules/stream-http/node_modules/readable-stream/CONTRIBUTING.md ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Developer's Certificate of Origin 1.1
2
+
3
+ By making a contribution to this project, I certify that:
4
+
5
+ * (a) The contribution was created in whole or in part by me and I
6
+ have the right to submit it under the open source license
7
+ indicated in the file; or
8
+
9
+ * (b) The contribution is based upon previous work that, to the best
10
+ of my knowledge, is covered under an appropriate open source
11
+ license and I have the right under that license to submit that
12
+ work with modifications, whether created in whole or in part
13
+ by me, under the same open source license (unless I am
14
+ permitted to submit under a different license), as indicated
15
+ in the file; or
16
+
17
+ * (c) The contribution was provided directly to me by some other
18
+ person who certified (a), (b) or (c) and I have not modified
19
+ it.
20
+
21
+ * (d) I understand and agree that this project and the contribution
22
+ are public and that a record of the contribution (including all
23
+ personal information I submit with it, including my sign-off) is
24
+ maintained indefinitely and may be redistributed consistent with
25
+ this project or the open source license(s) involved.
26
+
27
+ ## Moderation Policy
28
+
29
+ The [Node.js Moderation Policy] applies to this WG.
30
+
31
+ ## Code of Conduct
32
+
33
+ The [Node.js Code of Conduct][] applies to this WG.
34
+
35
+ [Node.js Code of Conduct]:
36
+ https://github.com/nodejs/node/blob/master/CODE_OF_CONDUCT.md
37
+ [Node.js Moderation Policy]:
38
+ https://github.com/nodejs/TSC/blob/master/Moderation-Policy.md
node_modules/stream-http/node_modules/readable-stream/GOVERNANCE.md ADDED
@@ -0,0 +1,136 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Streams Working Group
2
+
3
+ The Node.js Streams is jointly governed by a Working Group
4
+ (WG)
5
+ that is responsible for high-level guidance of the project.
6
+
7
+ The WG has final authority over this project including:
8
+
9
+ * Technical direction
10
+ * Project governance and process (including this policy)
11
+ * Contribution policy
12
+ * GitHub repository hosting
13
+ * Conduct guidelines
14
+ * Maintaining the list of additional Collaborators
15
+
16
+ For the current list of WG members, see the project
17
+ [README.md](./README.md#current-project-team-members).
18
+
19
+ ### Collaborators
20
+
21
+ The readable-stream GitHub repository is
22
+ maintained by the WG and additional Collaborators who are added by the
23
+ WG on an ongoing basis.
24
+
25
+ Individuals making significant and valuable contributions are made
26
+ Collaborators and given commit-access to the project. These
27
+ individuals are identified by the WG and their addition as
28
+ Collaborators is discussed during the WG meeting.
29
+
30
+ _Note:_ If you make a significant contribution and are not considered
31
+ for commit-access log an issue or contact a WG member directly and it
32
+ will be brought up in the next WG meeting.
33
+
34
+ Modifications of the contents of the readable-stream repository are
35
+ made on
36
+ a collaborative basis. Anybody with a GitHub account may propose a
37
+ modification via pull request and it will be considered by the project
38
+ Collaborators. All pull requests must be reviewed and accepted by a
39
+ Collaborator with sufficient expertise who is able to take full
40
+ responsibility for the change. In the case of pull requests proposed
41
+ by an existing Collaborator, an additional Collaborator is required
42
+ for sign-off. Consensus should be sought if additional Collaborators
43
+ participate and there is disagreement around a particular
44
+ modification. See _Consensus Seeking Process_ below for further detail
45
+ on the consensus model used for governance.
46
+
47
+ Collaborators may opt to elevate significant or controversial
48
+ modifications, or modifications that have not found consensus to the
49
+ WG for discussion by assigning the ***WG-agenda*** tag to a pull
50
+ request or issue. The WG should serve as the final arbiter where
51
+ required.
52
+
53
+ For the current list of Collaborators, see the project
54
+ [README.md](./README.md#members).
55
+
56
+ ### WG Membership
57
+
58
+ WG seats are not time-limited. There is no fixed size of the WG.
59
+ However, the expected target is between 6 and 12, to ensure adequate
60
+ coverage of important areas of expertise, balanced with the ability to
61
+ make decisions efficiently.
62
+
63
+ There is no specific set of requirements or qualifications for WG
64
+ membership beyond these rules.
65
+
66
+ The WG may add additional members to the WG by unanimous consensus.
67
+
68
+ A WG member may be removed from the WG by voluntary resignation, or by
69
+ unanimous consensus of all other WG members.
70
+
71
+ Changes to WG membership should be posted in the agenda, and may be
72
+ suggested as any other agenda item (see "WG Meetings" below).
73
+
74
+ If an addition or removal is proposed during a meeting, and the full
75
+ WG is not in attendance to participate, then the addition or removal
76
+ is added to the agenda for the subsequent meeting. This is to ensure
77
+ that all members are given the opportunity to participate in all
78
+ membership decisions. If a WG member is unable to attend a meeting
79
+ where a planned membership decision is being made, then their consent
80
+ is assumed.
81
+
82
+ No more than 1/3 of the WG members may be affiliated with the same
83
+ employer. If removal or resignation of a WG member, or a change of
84
+ employment by a WG member, creates a situation where more than 1/3 of
85
+ the WG membership shares an employer, then the situation must be
86
+ immediately remedied by the resignation or removal of one or more WG
87
+ members affiliated with the over-represented employer(s).
88
+
89
+ ### WG Meetings
90
+
91
+ The WG meets occasionally on a Google Hangout On Air. A designated moderator
92
+ approved by the WG runs the meeting. Each meeting should be
93
+ published to YouTube.
94
+
95
+ Items are added to the WG agenda that are considered contentious or
96
+ are modifications of governance, contribution policy, WG membership,
97
+ or release process.
98
+
99
+ The intention of the agenda is not to approve or review all patches;
100
+ that should happen continuously on GitHub and be handled by the larger
101
+ group of Collaborators.
102
+
103
+ Any community member or contributor can ask that something be added to
104
+ the next meeting's agenda by logging a GitHub Issue. Any Collaborator,
105
+ WG member or the moderator can add the item to the agenda by adding
106
+ the ***WG-agenda*** tag to the issue.
107
+
108
+ Prior to each WG meeting the moderator will share the Agenda with
109
+ members of the WG. WG members can add any items they like to the
110
+ agenda at the beginning of each meeting. The moderator and the WG
111
+ cannot veto or remove items.
112
+
113
+ The WG may invite persons or representatives from certain projects to
114
+ participate in a non-voting capacity.
115
+
116
+ The moderator is responsible for summarizing the discussion of each
117
+ agenda item and sends it as a pull request after the meeting.
118
+
119
+ ### Consensus Seeking Process
120
+
121
+ The WG follows a
122
+ [Consensus
123
+ Seeking](http://en.wikipedia.org/wiki/Consensus-seeking_decision-making)
124
+ decision-making model.
125
+
126
+ When an agenda item has appeared to reach a consensus the moderator
127
+ will ask "Does anyone object?" as a final call for dissent from the
128
+ consensus.
129
+
130
+ If an agenda item cannot reach a consensus a WG member can call for
131
+ either a closing vote or a vote to table the issue to the next
132
+ meeting. The call for a vote must be seconded by a majority of the WG
133
+ or else the discussion will continue. Simple majority wins.
134
+
135
+ Note that changes to WG membership require a majority consensus. See
136
+ "WG Membership" above.
node_modules/stream-http/node_modules/readable-stream/LICENSE ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Node.js is licensed for use as follows:
2
+
3
+ """
4
+ Copyright Node.js contributors. All rights reserved.
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to
8
+ deal in the Software without restriction, including without limitation the
9
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10
+ sell copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in
14
+ all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22
+ IN THE SOFTWARE.
23
+ """
24
+
25
+ This license applies to parts of Node.js originating from the
26
+ https://github.com/joyent/node repository:
27
+
28
+ """
29
+ Copyright Joyent, Inc. and other Node contributors. All rights reserved.
30
+ Permission is hereby granted, free of charge, to any person obtaining a copy
31
+ of this software and associated documentation files (the "Software"), to
32
+ deal in the Software without restriction, including without limitation the
33
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
34
+ sell copies of the Software, and to permit persons to whom the Software is
35
+ furnished to do so, subject to the following conditions:
36
+
37
+ The above copyright notice and this permission notice shall be included in
38
+ all copies or substantial portions of the Software.
39
+
40
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
41
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
42
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
43
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
44
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
45
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
46
+ IN THE SOFTWARE.
47
+ """
node_modules/stream-http/node_modules/readable-stream/README.md ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # readable-stream
2
+
3
+ ***Node.js core streams for userland*** [![Build Status](https://travis-ci.com/nodejs/readable-stream.svg?branch=master)](https://travis-ci.com/nodejs/readable-stream)
4
+
5
+
6
+ [![NPM](https://nodei.co/npm/readable-stream.png?downloads=true&downloadRank=true)](https://nodei.co/npm/readable-stream/)
7
+ [![NPM](https://nodei.co/npm-dl/readable-stream.png?&months=6&height=3)](https://nodei.co/npm/readable-stream/)
8
+
9
+
10
+ [![Sauce Test Status](https://saucelabs.com/browser-matrix/readabe-stream.svg)](https://saucelabs.com/u/readabe-stream)
11
+
12
+ ```bash
13
+ npm install --save readable-stream
14
+ ```
15
+
16
+ This package is a mirror of the streams implementations in Node.js.
17
+
18
+ Full documentation may be found on the [Node.js website](https://nodejs.org/dist/v10.18.1/docs/api/stream.html).
19
+
20
+ If you want to guarantee a stable streams base, regardless of what version of
21
+ 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).
22
+
23
+ As of version 2.0.0 **readable-stream** uses semantic versioning.
24
+
25
+ ## Version 3.x.x
26
+
27
+ v3.x.x of `readable-stream` is a cut from Node 10. This version supports Node 6, 8, and 10, as well as evergreen browsers, IE 11 and latest Safari. The breaking changes introduced by v3 are composed by the combined breaking changes in [Node v9](https://nodejs.org/en/blog/release/v9.0.0/) and [Node v10](https://nodejs.org/en/blog/release/v10.0.0/), as follows:
28
+
29
+ 1. Error codes: https://github.com/nodejs/node/pull/13310,
30
+ https://github.com/nodejs/node/pull/13291,
31
+ https://github.com/nodejs/node/pull/16589,
32
+ https://github.com/nodejs/node/pull/15042,
33
+ https://github.com/nodejs/node/pull/15665,
34
+ https://github.com/nodejs/readable-stream/pull/344
35
+ 2. 'readable' have precedence over flowing
36
+ https://github.com/nodejs/node/pull/18994
37
+ 3. make virtual methods errors consistent
38
+ https://github.com/nodejs/node/pull/18813
39
+ 4. updated streams error handling
40
+ https://github.com/nodejs/node/pull/18438
41
+ 5. writable.end should return this.
42
+ https://github.com/nodejs/node/pull/18780
43
+ 6. readable continues to read when push('')
44
+ https://github.com/nodejs/node/pull/18211
45
+ 7. add custom inspect to BufferList
46
+ https://github.com/nodejs/node/pull/17907
47
+ 8. always defer 'readable' with nextTick
48
+ https://github.com/nodejs/node/pull/17979
49
+
50
+ ## Version 2.x.x
51
+ v2.x.x of `readable-stream` is a cut of the stream module from Node 8 (there have been no semver-major changes from Node 4 to 8). This version supports all Node.js versions from 0.8, as well as evergreen browsers and IE 10 & 11.
52
+
53
+ ### Big Thanks
54
+
55
+ Cross-browser Testing Platform and Open Source <3 Provided by [Sauce Labs][sauce]
56
+
57
+ # Usage
58
+
59
+ You can swap your `require('stream')` with `require('readable-stream')`
60
+ without any changes, if you are just using one of the main classes and
61
+ functions.
62
+
63
+ ```js
64
+ const {
65
+ Readable,
66
+ Writable,
67
+ Transform,
68
+ Duplex,
69
+ pipeline,
70
+ finished
71
+ } = require('readable-stream')
72
+ ````
73
+
74
+ Note that `require('stream')` will return `Stream`, while
75
+ `require('readable-stream')` will return `Readable`. We discourage using
76
+ whatever is exported directly, but rather use one of the properties as
77
+ shown in the example above.
78
+
79
+ # Streams Working Group
80
+
81
+ `readable-stream` is maintained by the Streams Working Group, which
82
+ oversees the development and maintenance of the Streams API within
83
+ Node.js. The responsibilities of the Streams Working Group include:
84
+
85
+ * Addressing stream issues on the Node.js issue tracker.
86
+ * Authoring and editing stream documentation within the Node.js project.
87
+ * Reviewing changes to stream subclasses within the Node.js project.
88
+ * Redirecting changes to streams from the Node.js project to this
89
+ project.
90
+ * Assisting in the implementation of stream providers within Node.js.
91
+ * Recommending versions of `readable-stream` to be included in Node.js.
92
+ * Messaging about the future of streams to give the community advance
93
+ notice of changes.
94
+
95
+ <a name="members"></a>
96
+ ## Team Members
97
+
98
+ * **Calvin Metcalf** ([@calvinmetcalf](https://github.com/calvinmetcalf)) &lt;calvin.metcalf@gmail.com&gt;
99
+ - Release GPG key: F3EF5F62A87FC27A22E643F714CE4FF5015AA242
100
+ * **Mathias Buus** ([@mafintosh](https://github.com/mafintosh)) &lt;mathiasbuus@gmail.com&gt;
101
+ * **Matteo Collina** ([@mcollina](https://github.com/mcollina)) &lt;matteo.collina@gmail.com&gt;
102
+ - Release GPG key: 3ABC01543F22DD2239285CDD818674489FBC127E
103
+ * **Irina Shestak** ([@lrlna](https://github.com/lrlna)) &lt;shestak.irina@gmail.com&gt;
104
+ * **Yoshua Wyuts** ([@yoshuawuyts](https://github.com/yoshuawuyts)) &lt;yoshuawuyts@gmail.com&gt;
105
+
106
+ [sauce]: https://saucelabs.com