fsevents 1.2.3 → 1.2.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of fsevents might be problematic. Click here for more details.

Files changed (208) hide show
  1. package/.travis.yml +2 -3
  2. package/fsevents.cc +14 -26
  3. package/node_modules/abbrev/package.json +13 -14
  4. package/node_modules/ansi-regex/package.json +13 -14
  5. package/node_modules/aproba/package.json +13 -14
  6. package/node_modules/are-we-there-yet/CHANGES.md +6 -0
  7. package/node_modules/are-we-there-yet/package.json +19 -20
  8. package/node_modules/are-we-there-yet/tracker-stream.js +1 -0
  9. package/node_modules/balanced-match/package.json +13 -14
  10. package/node_modules/brace-expansion/package.json +13 -14
  11. package/node_modules/chownr/chownr.js +113 -40
  12. package/node_modules/chownr/package.json +22 -20
  13. package/node_modules/code-point-at/package.json +13 -14
  14. package/node_modules/concat-map/package.json +8 -9
  15. package/node_modules/console-control-strings/package.json +14 -14
  16. package/node_modules/core-util-is/package.json +13 -14
  17. package/node_modules/debug/CHANGELOG.md +34 -1
  18. package/node_modules/debug/README.md +188 -63
  19. package/node_modules/debug/dist/debug.js +886 -0
  20. package/node_modules/debug/package.json +34 -33
  21. package/node_modules/debug/src/browser.js +77 -82
  22. package/node_modules/debug/src/common.js +249 -0
  23. package/node_modules/debug/src/index.js +5 -3
  24. package/node_modules/debug/src/node.js +72 -146
  25. package/node_modules/deep-extend/CHANGELOG.md +28 -3
  26. package/node_modules/deep-extend/LICENSE +1 -1
  27. package/node_modules/deep-extend/README.md +2 -1
  28. package/node_modules/deep-extend/lib/deep-extend.js +11 -5
  29. package/node_modules/deep-extend/package.json +26 -28
  30. package/node_modules/delegates/package.json +13 -14
  31. package/node_modules/detect-libc/package.json +13 -14
  32. package/node_modules/fs-minipass/index.js +2 -1
  33. package/node_modules/fs-minipass/package.json +24 -22
  34. package/node_modules/fs.realpath/package.json +13 -14
  35. package/node_modules/gauge/package.json +13 -14
  36. package/node_modules/glob/LICENSE +6 -0
  37. package/node_modules/glob/README.md +8 -1
  38. package/node_modules/glob/package.json +21 -19
  39. package/node_modules/has-unicode/package.json +13 -14
  40. package/node_modules/iconv-lite/Changelog.md +16 -0
  41. package/node_modules/iconv-lite/encodings/sbcs-codec.js +2 -2
  42. package/node_modules/iconv-lite/encodings/sbcs-data.js +5 -0
  43. package/node_modules/iconv-lite/lib/extend-node.js +1 -1
  44. package/node_modules/iconv-lite/lib/index.d.ts +2 -2
  45. package/node_modules/iconv-lite/package.json +19 -20
  46. package/node_modules/ignore-walk/README.md +1 -1
  47. package/node_modules/ignore-walk/index.js +9 -5
  48. package/node_modules/ignore-walk/package.json +22 -20
  49. package/node_modules/inflight/package.json +13 -14
  50. package/node_modules/inherits/inherits.js +2 -0
  51. package/node_modules/inherits/inherits_browser.js +18 -14
  52. package/node_modules/inherits/package.json +20 -20
  53. package/node_modules/ini/package.json +13 -14
  54. package/node_modules/is-fullwidth-code-point/package.json +13 -14
  55. package/node_modules/isarray/package.json +13 -14
  56. package/node_modules/minimatch/package.json +14 -14
  57. package/node_modules/minimist/package.json +8 -9
  58. package/node_modules/minipass/LICENSE +15 -0
  59. package/node_modules/minipass/README.md +567 -7
  60. package/node_modules/minipass/index.js +255 -22
  61. package/node_modules/minipass/package.json +26 -22
  62. package/node_modules/minizlib/README.md +36 -27
  63. package/node_modules/minizlib/constants.js +73 -4
  64. package/node_modules/minizlib/index.js +188 -232
  65. package/node_modules/minizlib/package.json +19 -20
  66. package/node_modules/mkdirp/package.json +14 -14
  67. package/node_modules/ms/index.js +29 -19
  68. package/node_modules/ms/package.json +22 -23
  69. package/node_modules/ms/readme.md +18 -9
  70. package/node_modules/needle/README.md +3 -3
  71. package/node_modules/needle/examples/multipart-stream.js +1 -1
  72. package/node_modules/needle/lib/auth.js +1 -1
  73. package/node_modules/needle/lib/cookies.js +12 -10
  74. package/node_modules/needle/lib/multipart.js +1 -1
  75. package/node_modules/needle/lib/needle.js +20 -6
  76. package/node_modules/needle/package.json +26 -27
  77. package/node_modules/needle/test/basic_auth_spec.js +1 -1
  78. package/node_modules/needle/test/cookies_spec.js +2 -2
  79. package/node_modules/needle/test/errors_spec.js +4 -4
  80. package/node_modules/needle/test/headers_spec.js +1 -1
  81. package/node_modules/needle/test/long_string_spec.js +1 -1
  82. package/node_modules/needle/test/output_spec.js +1 -1
  83. package/node_modules/needle/test/post_data_spec.js +20 -20
  84. package/node_modules/needle/test/proxy_spec.js +1 -1
  85. package/node_modules/needle/test/url_spec.js +11 -3
  86. package/node_modules/needle/test/utils/test.js +1 -1
  87. package/node_modules/node-pre-gyp/CHANGELOG.md +34 -3
  88. package/node_modules/node-pre-gyp/README.md +53 -21
  89. package/node_modules/node-pre-gyp/appveyor.yml +2 -9
  90. package/node_modules/node-pre-gyp/contributing.md +2 -2
  91. package/node_modules/node-pre-gyp/lib/build.js +1 -1
  92. package/node_modules/node-pre-gyp/lib/install.js +46 -12
  93. package/node_modules/node-pre-gyp/lib/node-pre-gyp.js +1 -1
  94. package/node_modules/node-pre-gyp/lib/package.js +5 -2
  95. package/node_modules/node-pre-gyp/lib/pre-binding.js +5 -5
  96. package/node_modules/node-pre-gyp/lib/rebuild.js +1 -1
  97. package/node_modules/node-pre-gyp/lib/reinstall.js +1 -1
  98. package/node_modules/node-pre-gyp/lib/util/abi_crosswalk.json +148 -0
  99. package/node_modules/node-pre-gyp/lib/util/handle_gyp_opts.js +5 -2
  100. package/node_modules/node-pre-gyp/lib/util/napi.js +70 -22
  101. package/node_modules/node-pre-gyp/lib/util/versioning.js +7 -6
  102. package/node_modules/node-pre-gyp/package.json +16 -20
  103. package/node_modules/nopt/package.json +13 -14
  104. package/node_modules/npm-bundled/LICENSE +15 -0
  105. package/node_modules/npm-bundled/README.md +2 -0
  106. package/node_modules/npm-bundled/index.js +29 -7
  107. package/node_modules/npm-bundled/package.json +21 -19
  108. package/node_modules/npm-normalize-package-bin/.github/settings.yml +2 -0
  109. package/node_modules/npm-normalize-package-bin/.npmignore +24 -0
  110. package/node_modules/npm-normalize-package-bin/LICENSE +15 -0
  111. package/node_modules/npm-normalize-package-bin/README.md +14 -0
  112. package/node_modules/npm-normalize-package-bin/index.js +60 -0
  113. package/node_modules/npm-normalize-package-bin/package-lock.json +3529 -0
  114. package/node_modules/npm-normalize-package-bin/package.json +57 -0
  115. package/node_modules/npm-normalize-package-bin/test/array.js +37 -0
  116. package/node_modules/npm-normalize-package-bin/test/nobin.js +35 -0
  117. package/node_modules/npm-normalize-package-bin/test/object.js +141 -0
  118. package/node_modules/npm-normalize-package-bin/test/string.js +37 -0
  119. package/node_modules/npm-packlist/index.js +90 -21
  120. package/node_modules/npm-packlist/package.json +27 -21
  121. package/node_modules/npmlog/package.json +13 -14
  122. package/node_modules/number-is-nan/package.json +13 -14
  123. package/node_modules/object-assign/package.json +13 -14
  124. package/node_modules/once/package.json +14 -14
  125. package/node_modules/os-homedir/package.json +13 -14
  126. package/node_modules/os-tmpdir/package.json +13 -14
  127. package/node_modules/osenv/package.json +13 -14
  128. package/node_modules/path-is-absolute/package.json +13 -14
  129. package/node_modules/process-nextick-args/index.js +2 -1
  130. package/node_modules/process-nextick-args/package.json +17 -18
  131. package/node_modules/rc/node_modules/minimist/package.json +13 -14
  132. package/node_modules/rc/package.json +18 -19
  133. package/node_modules/readable-stream/package.json +13 -14
  134. package/node_modules/rimraf/package.json +22 -20
  135. package/node_modules/rimraf/rimraf.js +9 -1
  136. package/node_modules/safe-buffer/index.d.ts +187 -0
  137. package/node_modules/safe-buffer/package.json +23 -21
  138. package/node_modules/safer-buffer/package.json +13 -14
  139. package/node_modules/sax/package.json +13 -14
  140. package/node_modules/semver/CHANGELOG.md +39 -0
  141. package/node_modules/semver/README.md +43 -19
  142. package/node_modules/semver/bin/semver +92 -75
  143. package/node_modules/semver/package.json +25 -20
  144. package/node_modules/semver/semver.js +922 -763
  145. package/node_modules/set-blocking/package.json +13 -14
  146. package/node_modules/signal-exit/package.json +13 -14
  147. package/node_modules/string-width/package.json +14 -14
  148. package/node_modules/string_decoder/package.json +13 -14
  149. package/node_modules/strip-ansi/package.json +14 -14
  150. package/node_modules/strip-json-comments/package.json +13 -14
  151. package/node_modules/tar/README.md +7 -2
  152. package/node_modules/tar/lib/header.js +20 -4
  153. package/node_modules/tar/lib/large-numbers.js +32 -27
  154. package/node_modules/tar/lib/mkdir.js +2 -2
  155. package/node_modules/tar/lib/mode-fix.js +14 -0
  156. package/node_modules/tar/lib/pack.js +1 -0
  157. package/node_modules/tar/lib/parse.js +7 -1
  158. package/node_modules/tar/lib/read-entry.js +4 -0
  159. package/node_modules/tar/lib/unpack.js +67 -6
  160. package/node_modules/tar/lib/write-entry.js +25 -6
  161. package/node_modules/tar/package.json +33 -30
  162. package/node_modules/util-deprecate/package.json +13 -14
  163. package/node_modules/wide-align/package.json +19 -20
  164. package/node_modules/wrappy/package.json +14 -14
  165. package/node_modules/yallist/iterator.js +5 -5
  166. package/node_modules/yallist/package.json +19 -19
  167. package/node_modules/yallist/yallist.js +52 -2
  168. package/package.json +6 -9
  169. package/src/async.cc +2 -2
  170. package/src/constants.cc +20 -20
  171. package/src/thread.cc +5 -6
  172. package/.npmignore +0 -1
  173. package/build/.target.mk +0 -53
  174. package/build/Makefile +0 -352
  175. package/build/Release/.deps/Release/.node.d +0 -1
  176. package/build/Release/.deps/Release/fse.node.d +0 -1
  177. package/build/Release/.deps/Release/obj.target/action_after_build.stamp.d +0 -1
  178. package/build/Release/.deps/Release/obj.target/fse/fsevents.o.d +0 -65
  179. package/build/Release/.deps/Users/eshanker/Code/fsevents/lib/binding/Release/node-v48-darwin-x64/fse.node.d +0 -1
  180. package/build/Release/.node +0 -0
  181. package/build/Release/fse.node +0 -0
  182. package/build/Release/obj.target/action_after_build.stamp +0 -0
  183. package/build/Release/obj.target/fse/fsevents.o +0 -0
  184. package/build/action_after_build.target.mk +0 -32
  185. package/build/binding.Makefile +0 -6
  186. package/build/fse.target.mk +0 -179
  187. package/build/gyp-mac-tool +0 -611
  188. package/build/stage/v1.1.2/fse-v1.1.2-node-v48-darwin-x64.tar.gz +0 -0
  189. package/lib/binding/Release/node-v11-darwin-x64/fse.node +0 -0
  190. package/lib/binding/Release/node-v46-darwin-x64/fse.node +0 -0
  191. package/lib/binding/Release/node-v47-darwin-x64/fse.node +0 -0
  192. package/lib/binding/Release/node-v48-darwin-x64/fse.node +0 -0
  193. package/lib/binding/Release/node-v57-darwin-x64/fse.node +0 -0
  194. package/node_modules/are-we-there-yet/CHANGES.md~ +0 -27
  195. package/node_modules/debug/.coveralls.yml +0 -1
  196. package/node_modules/debug/.eslintrc +0 -11
  197. package/node_modules/debug/.npmignore +0 -9
  198. package/node_modules/debug/.travis.yml +0 -14
  199. package/node_modules/debug/Makefile +0 -50
  200. package/node_modules/debug/component.json +0 -19
  201. package/node_modules/debug/karma.conf.js +0 -70
  202. package/node_modules/debug/src/debug.js +0 -202
  203. package/node_modules/debug/src/inspector-log.js +0 -15
  204. package/node_modules/iconv-lite/.travis.yml +0 -23
  205. package/node_modules/rc/.npmignore +0 -3
  206. package/node_modules/safe-buffer/.travis.yml +0 -7
  207. package/node_modules/safe-buffer/test.js +0 -101
  208. package/src/locking.cc +0 -27
@@ -15,9 +15,7 @@ cases where PassThrough is a good idea.
15
15
  There is a `read()` method, but it's much more efficient to consume
16
16
  data from this stream via `'data'` events or by calling `pipe()` into
17
17
  some other stream. Calling `read()` requires the buffer to be
18
- flattened in some cases, which requires copying memory. Also,
19
- `read()` always returns Buffers, even if an `encoding` option is
20
- specified.
18
+ flattened in some cases, which requires copying memory.
21
19
 
22
20
  There is also no `unpipe()` method. Once you start piping, there is
23
21
  no stopping it!
@@ -26,21 +24,583 @@ If you set `objectMode: true` in the options, then whatever is written
26
24
  will be emitted. Otherwise, it'll do a minimal amount of Buffer
27
25
  copying to ensure proper Streams semantics when `read(n)` is called.
28
26
 
27
+ `objectMode` can also be set by doing `stream.objectMode = true`, or by
28
+ writing any non-string/non-buffer data. `objectMode` cannot be set to
29
+ false once it is set.
30
+
29
31
  This is not a `through` or `through2` stream. It doesn't transform
30
32
  the data, it just passes it right through. If you want to transform
31
33
  the data, extend the class, and override the `write()` method. Once
32
34
  you're done transforming the data however you want, call
33
35
  `super.write()` with the transform output.
34
36
 
35
- For an example of a stream that extends MiniPass to provide transform
36
- capabilities, check out [minizlib](http://npm.im/minizlib).
37
+ For some examples of streams that extend Minipass in various ways, check
38
+ out:
39
+
40
+ - [minizlib](http://npm.im/minizlib)
41
+ - [fs-minipass](http://npm.im/fs-minipass)
42
+ - [tar](http://npm.im/tar)
43
+ - [minipass-collect](http://npm.im/minipass-collect)
44
+ - [minipass-flush](http://npm.im/minipass-flush)
45
+ - [minipass-pipeline](http://npm.im/minipass-pipeline)
46
+ - [tap](http://npm.im/tap)
47
+ - [tap-parser](http://npm.im/tap)
48
+ - [treport](http://npm.im/tap)
49
+
50
+ ## Differences from Node.js Streams
51
+
52
+ There are several things that make Minipass streams different from (and in
53
+ some ways superior to) Node.js core streams.
54
+
55
+ Please read these caveats if you are familiar with noode-core streams and
56
+ intend to use Minipass streams in your programs.
57
+
58
+ ### Timing
59
+
60
+ Minipass streams are designed to support synchronous use-cases. Thus, data
61
+ is emitted as soon as it is available, always. It is buffered until read,
62
+ but no longer. Another way to look at it is that Minipass streams are
63
+ exactly as synchronous as the logic that writes into them.
64
+
65
+ This can be surprising if your code relies on `PassThrough.write()` always
66
+ providing data on the next tick rather than the current one, or being able
67
+ to call `resume()` and not have the entire buffer disappear immediately.
68
+
69
+ However, without this synchronicity guarantee, there would be no way for
70
+ Minipass to achieve the speeds it does, or support the synchronous use
71
+ cases that it does. Simply put, waiting takes time.
72
+
73
+ This non-deferring approach makes Minipass streams much easier to reason
74
+ about, especially in the context of Promises and other flow-control
75
+ mechanisms.
76
+
77
+ ### No High/Low Water Marks
78
+
79
+ Node.js core streams will optimistically fill up a buffer, returning `true`
80
+ on all writes until the limit is hit, even if the data has nowhere to go.
81
+ Then, they will not attempt to draw more data in until the buffer size dips
82
+ below a minimum value.
83
+
84
+ Minipass streams are much simpler. The `write()` method will return `true`
85
+ if the data has somewhere to go (which is to say, given the timing
86
+ guarantees, that the data is already there by the time `write()` returns).
87
+
88
+ If the data has nowhere to go, then `write()` returns false, and the data
89
+ sits in a buffer, to be drained out immediately as soon as anyone consumes
90
+ it.
91
+
92
+ ### Hazards of Buffering (or: Why Minipass Is So Fast)
93
+
94
+ Since data written to a Minipass stream is immediately written all the way
95
+ through the pipeline, and `write()` always returns true/false based on
96
+ whether the data was fully flushed, backpressure is communicated
97
+ immediately to the upstream caller. This minimizes buffering.
98
+
99
+ Consider this case:
100
+
101
+ ```js
102
+ const {PassThrough} = require('stream')
103
+ const p1 = new PassThrough({ highWaterMark: 1024 })
104
+ const p2 = new PassThrough({ highWaterMark: 1024 })
105
+ const p3 = new PassThrough({ highWaterMark: 1024 })
106
+ const p4 = new PassThrough({ highWaterMark: 1024 })
107
+
108
+ p1.pipe(p2).pipe(p3).pipe(p4)
109
+ p4.on('data', () => console.log('made it through'))
110
+
111
+ // this returns false and buffers, then writes to p2 on next tick (1)
112
+ // p2 returns false and buffers, pausing p1, then writes to p3 on next tick (2)
113
+ // p3 returns false and buffers, pausing p2, then writes to p4 on next tick (3)
114
+ // p4 returns false and buffers, pausing p3, then emits 'data' and 'drain'
115
+ // on next tick (4)
116
+ // p3 sees p4's 'drain' event, and calls resume(), emitting 'resume' and
117
+ // 'drain' on next tick (5)
118
+ // p2 sees p3's 'drain', calls resume(), emits 'resume' and 'drain' on next tick (6)
119
+ // p1 sees p2's 'drain', calls resume(), emits 'resume' and 'drain' on next
120
+ // tick (7)
121
+
122
+ p1.write(Buffer.alloc(2048)) // returns false
123
+ ```
124
+
125
+ Along the way, the data was buffered and deferred at each stage, and
126
+ multiple event deferrals happened, for an unblocked pipeline where it was
127
+ perfectly safe to write all the way through!
128
+
129
+ Furthermore, setting a `highWaterMark` of `1024` might lead someone reading
130
+ the code to think an advisory maximum of 1KiB is being set for the
131
+ pipeline. However, the actual advisory buffering level is the _sum_ of
132
+ `highWaterMark` values, since each one has its own bucket.
133
+
134
+ Consider the Minipass case:
135
+
136
+ ```js
137
+ const m1 = new Minipass()
138
+ const m2 = new Minipass()
139
+ const m3 = new Minipass()
140
+ const m4 = new Minipass()
141
+
142
+ m1.pipe(m2).pipe(m3).pipe(m4)
143
+ m4.on('data', () => console.log('made it through'))
144
+
145
+ // m1 is flowing, so it writes the data to m2 immediately
146
+ // m2 is flowing, so it writes the data to m3 immediately
147
+ // m3 is flowing, so it writes the data to m4 immediately
148
+ // m4 is flowing, so it fires the 'data' event immediately, returns true
149
+ // m4's write returned true, so m3 is still flowing, returns true
150
+ // m3's write returned true, so m2 is still flowing, returns true
151
+ // m2's write returned true, so m1 is still flowing, returns true
152
+ // No event deferrals or buffering along the way!
153
+
154
+ m1.write(Buffer.alloc(2048)) // returns true
155
+ ```
156
+
157
+ It is extremely unlikely that you _don't_ want to buffer any data written,
158
+ or _ever_ buffer data that can be flushed all the way through. Neither
159
+ node-core streams nor Minipass ever fail to buffer written data, but
160
+ node-core streams do a lot of unnecessary buffering and pausing.
161
+
162
+ As always, the faster implementation is the one that does less stuff and
163
+ waits less time to do it.
164
+
165
+ ### Immediately emit `end` for empty streams (when not paused)
166
+
167
+ If a stream is not paused, and `end()` is called before writing any data
168
+ into it, then it will emit `end` immediately.
169
+
170
+ If you have logic that occurs on the `end` event which you don't want to
171
+ potentially happen immediately (for example, closing file descriptors,
172
+ moving on to the next entry in an archive parse stream, etc.) then be sure
173
+ to call `stream.pause()` on creation, and then `stream.resume()` once you
174
+ are ready to respond to the `end` event.
175
+
176
+ ### Emit `end` When Asked
177
+
178
+ One hazard of immediately emitting `'end'` is that you may not yet have had
179
+ a chance to add a listener. In order to avoid this hazard, Minipass
180
+ streams safely re-emit the `'end'` event if a new listener is added after
181
+ `'end'` has been emitted.
182
+
183
+ Ie, if you do `stream.on('end', someFunction)`, and the stream has already
184
+ emitted `end`, then it will call the handler right away. (You can think of
185
+ this somewhat like attaching a new `.then(fn)` to a previously-resolved
186
+ Promise.)
187
+
188
+ To prevent calling handlers multiple times who would not expect multiple
189
+ ends to occur, all listeners are removed from the `'end'` event whenever it
190
+ is emitted.
191
+
192
+ ### Impact of "immediate flow" on Tee-streams
193
+
194
+ A "tee stream" is a stream piping to multiple destinations:
195
+
196
+ ```js
197
+ const tee = new Minipass()
198
+ t.pipe(dest1)
199
+ t.pipe(dest2)
200
+ t.write('foo') // goes to both destinations
201
+ ```
202
+
203
+ Since Minipass streams _immediately_ process any pending data through the
204
+ pipeline when a new pipe destination is added, this can have surprising
205
+ effects, especially when a stream comes in from some other function and may
206
+ or may not have data in its buffer.
207
+
208
+ ```js
209
+ // WARNING! WILL LOSE DATA!
210
+ const src = new Minipass()
211
+ src.write('foo')
212
+ src.pipe(dest1) // 'foo' chunk flows to dest1 immediately, and is gone
213
+ src.pipe(dest2) // gets nothing!
214
+ ```
215
+
216
+ The solution is to create a dedicated tee-stream junction that pipes to
217
+ both locations, and then pipe to _that_ instead.
218
+
219
+ ```js
220
+ // Safe example: tee to both places
221
+ const src = new Minipass()
222
+ src.write('foo')
223
+ const tee = new Minipass()
224
+ tee.pipe(dest1)
225
+ tee.pipe(dest2)
226
+ stream.pipe(tee) // tee gets 'foo', pipes to both locations
227
+ ```
228
+
229
+ The same caveat applies to `on('data')` event listeners. The first one
230
+ added will _immediately_ receive all of the data, leaving nothing for the
231
+ second:
232
+
233
+ ```js
234
+ // WARNING! WILL LOSE DATA!
235
+ const src = new Minipass()
236
+ src.write('foo')
237
+ src.on('data', handler1) // receives 'foo' right away
238
+ src.on('data', handler2) // nothing to see here!
239
+ ```
240
+
241
+ Using a dedicated tee-stream can be used in this case as well:
242
+
243
+ ```js
244
+ // Safe example: tee to both data handlers
245
+ const src = new Minipass()
246
+ src.write('foo')
247
+ const tee = new Minipass()
248
+ tee.on('data', handler1)
249
+ tee.on('data', handler2)
250
+ src.pipe(tee)
251
+ ```
37
252
 
38
253
  ## USAGE
39
254
 
255
+ It's a stream! Use it like a stream and it'll most likely do what you want.
256
+
40
257
  ```js
41
- const MiniPass = require('minipass')
42
- const mp = new MiniPass(options) // optional: { encoding }
258
+ const Minipass = require('minipass')
259
+ const mp = new Minipass(options) // optional: { encoding, objectMode }
43
260
  mp.write('foo')
44
261
  mp.pipe(someOtherStream)
45
262
  mp.end('bar')
46
263
  ```
264
+
265
+ ### OPTIONS
266
+
267
+ * `encoding` How would you like the data coming _out_ of the stream to be
268
+ encoded? Accepts any values that can be passed to `Buffer.toString()`.
269
+ * `objectMode` Emit data exactly as it comes in. This will be flipped on
270
+ by default if you write() something other than a string or Buffer at any
271
+ point. Setting `objectMode: true` will prevent setting any encoding
272
+ value.
273
+
274
+ ### API
275
+
276
+ Implements the user-facing portions of Node.js's `Readable` and `Writable`
277
+ streams.
278
+
279
+ ### Methods
280
+
281
+ * `write(chunk, [encoding], [callback])` - Put data in. (Note that, in the
282
+ base Minipass class, the same data will come out.) Returns `false` if
283
+ the stream will buffer the next write, or true if it's still in
284
+ "flowing" mode.
285
+ * `end([chunk, [encoding]], [callback])` - Signal that you have no more
286
+ data to write. This will queue an `end` event to be fired when all the
287
+ data has been consumed.
288
+ * `setEncoding(encoding)` - Set the encoding for data coming of the
289
+ stream. This can only be done once.
290
+ * `pause()` - No more data for a while, please. This also prevents `end`
291
+ from being emitted for empty streams until the stream is resumed.
292
+ * `resume()` - Resume the stream. If there's data in the buffer, it is
293
+ all discarded. Any buffered events are immediately emitted.
294
+ * `pipe(dest)` - Send all output to the stream provided. There is no way
295
+ to unpipe. When data is emitted, it is immediately written to any and
296
+ all pipe destinations.
297
+ * `on(ev, fn)`, `emit(ev, fn)` - Minipass streams are EventEmitters.
298
+ Some events are given special treatment, however. (See below under
299
+ "events".)
300
+ * `promise()` - Returns a Promise that resolves when the stream emits
301
+ `end`, or rejects if the stream emits `error`.
302
+ * `collect()` - Return a Promise that resolves on `end` with an array
303
+ containing each chunk of data that was emitted, or rejects if the
304
+ stream emits `error`. Note that this consumes the stream data.
305
+ * `concat()` - Same as `collect()`, but concatenates the data into a
306
+ single Buffer object. Will reject the returned promise if the stream is
307
+ in objectMode, or if it goes into objectMode by the end of the data.
308
+ * `read(n)` - Consume `n` bytes of data out of the buffer. If `n` is not
309
+ provided, then consume all of it. If `n` bytes are not available, then
310
+ it returns null. **Note** consuming streams in this way is less
311
+ efficient, and can lead to unnecessary Buffer copying.
312
+ * `destroy([er])` - Destroy the stream. If an error is provided, then an
313
+ `'error'` event is emitted. If the stream has a `close()` method, and
314
+ has not emitted a `'close'` event yet, then `stream.close()` will be
315
+ called. Any Promises returned by `.promise()`, `.collect()` or
316
+ `.concat()` will be rejected. After being destroyed, writing to the
317
+ stream will emit an error. No more data will be emitted if the stream is
318
+ destroyed, even if it was previously buffered.
319
+
320
+ ### Properties
321
+
322
+ * `bufferLength` Read-only. Total number of bytes buffered, or in the case
323
+ of objectMode, the total number of objects.
324
+ * `encoding` The encoding that has been set. (Setting this is equivalent
325
+ to calling `setEncoding(enc)` and has the same prohibition against
326
+ setting multiple times.)
327
+ * `flowing` Read-only. Boolean indicating whether a chunk written to the
328
+ stream will be immediately emitted.
329
+ * `emittedEnd` Read-only. Boolean indicating whether the end-ish events
330
+ (ie, `end`, `prefinish`, `finish`) have been emitted. Note that
331
+ listening on any end-ish event will immediateyl re-emit it if it has
332
+ already been emitted.
333
+ * `writable` Whether the stream is writable. Default `true`. Set to
334
+ `false` when `end()`
335
+ * `readable` Whether the stream is readable. Default `true`.
336
+ * `buffer` A [yallist](http://npm.im/yallist) linked list of chunks written
337
+ to the stream that have not yet been emitted. (It's probably a bad idea
338
+ to mess with this.)
339
+ * `pipes` A [yallist](http://npm.im/yallist) linked list of streams that
340
+ this stream is piping into. (It's probably a bad idea to mess with
341
+ this.)
342
+ * `destroyed` A getter that indicates whether the stream was destroyed.
343
+ * `paused` True if the stream has been explicitly paused, otherwise false.
344
+ * `objectMode` Indicates whether the stream is in `objectMode`. Once set
345
+ to `true`, it cannot be set to `false`.
346
+
347
+ ### Events
348
+
349
+ * `data` Emitted when there's data to read. Argument is the data to read.
350
+ This is never emitted while not flowing. If a listener is attached, that
351
+ will resume the stream.
352
+ * `end` Emitted when there's no more data to read. This will be emitted
353
+ immediately for empty streams when `end()` is called. If a listener is
354
+ attached, and `end` was already emitted, then it will be emitted again.
355
+ All listeners are removed when `end` is emitted.
356
+ * `prefinish` An end-ish event that follows the same logic as `end` and is
357
+ emitted in the same conditions where `end` is emitted. Emitted after
358
+ `'end'`.
359
+ * `finish` An end-ish event that follows the same logic as `end` and is
360
+ emitted in the same conditions where `end` is emitted. Emitted after
361
+ `'prefinish'`.
362
+ * `close` An indication that an underlying resource has been released.
363
+ Minipass does not emit this event, but will defer it until after `end`
364
+ has been emitted, since it throws off some stream libraries otherwise.
365
+ * `drain` Emitted when the internal buffer empties, and it is again
366
+ suitable to `write()` into the stream.
367
+ * `readable` Emitted when data is buffered and ready to be read by a
368
+ consumer.
369
+ * `resume` Emitted when stream changes state from buffering to flowing
370
+ mode. (Ie, when `resume` is called, `pipe` is called, or a `data` event
371
+ listener is added.)
372
+
373
+ ### Static Methods
374
+
375
+ * `Minipass.isStream(stream)` Returns `true` if the argument is a stream,
376
+ and false otherwise. To be considered a stream, the object must be
377
+ either an instance of Minipass, or an EventEmitter that has either a
378
+ `pipe()` method, or both `write()` and `end()` methods. (Pretty much any
379
+ stream in node-land will return `true` for this.)
380
+
381
+ ## EXAMPLES
382
+
383
+ Here are some examples of things you can do with Minipass streams.
384
+
385
+ ### simple "are you done yet" promise
386
+
387
+ ```js
388
+ mp.promise().then(() => {
389
+ // stream is finished
390
+ }, er => {
391
+ // stream emitted an error
392
+ })
393
+ ```
394
+
395
+ ### collecting
396
+
397
+ ```js
398
+ mp.collect().then(all => {
399
+ // all is an array of all the data emitted
400
+ // encoding is supported in this case, so
401
+ // so the result will be a collection of strings if
402
+ // an encoding is specified, or buffers/objects if not.
403
+ //
404
+ // In an async function, you may do
405
+ // const data = await stream.collect()
406
+ })
407
+ ```
408
+
409
+ ### collecting into a single blob
410
+
411
+ This is a bit slower because it concatenates the data into one chunk for
412
+ you, but if you're going to do it yourself anyway, it's convenient this
413
+ way:
414
+
415
+ ```js
416
+ mp.concat().then(onebigchunk => {
417
+ // onebigchunk is a string if the stream
418
+ // had an encoding set, or a buffer otherwise.
419
+ })
420
+ ```
421
+
422
+ ### iteration
423
+
424
+ You can iterate over streams synchronously or asynchronously in
425
+ platforms that support it.
426
+
427
+ Synchronous iteration will end when the currently available data is
428
+ consumed, even if the `end` event has not been reached. In string and
429
+ buffer mode, the data is concatenated, so unless multiple writes are
430
+ occurring in the same tick as the `read()`, sync iteration loops will
431
+ generally only have a single iteration.
432
+
433
+ To consume chunks in this way exactly as they have been written, with
434
+ no flattening, create the stream with the `{ objectMode: true }`
435
+ option.
436
+
437
+ ```js
438
+ const mp = new Minipass({ objectMode: true })
439
+ mp.write('a')
440
+ mp.write('b')
441
+ for (let letter of mp) {
442
+ console.log(letter) // a, b
443
+ }
444
+ mp.write('c')
445
+ mp.write('d')
446
+ for (let letter of mp) {
447
+ console.log(letter) // c, d
448
+ }
449
+ mp.write('e')
450
+ mp.end()
451
+ for (let letter of mp) {
452
+ console.log(letter) // e
453
+ }
454
+ for (let letter of mp) {
455
+ console.log(letter) // nothing
456
+ }
457
+ ```
458
+
459
+ Asynchronous iteration will continue until the end event is reached,
460
+ consuming all of the data.
461
+
462
+ ```js
463
+ const mp = new Minipass({ encoding: 'utf8' })
464
+
465
+ // some source of some data
466
+ let i = 5
467
+ const inter = setInterval(() => {
468
+ if (i --> 0)
469
+ mp.write(Buffer.from('foo\n', 'utf8'))
470
+ else {
471
+ mp.end()
472
+ clearInterval(inter)
473
+ }
474
+ }, 100)
475
+
476
+ // consume the data with asynchronous iteration
477
+ async function consume () {
478
+ for await (let chunk of mp) {
479
+ console.log(chunk)
480
+ }
481
+ return 'ok'
482
+ }
483
+
484
+ consume().then(res => console.log(res))
485
+ // logs `foo\n` 5 times, and then `ok`
486
+ ```
487
+
488
+ ### subclass that `console.log()`s everything written into it
489
+
490
+ ```js
491
+ class Logger extends Minipass {
492
+ write (chunk, encoding, callback) {
493
+ console.log('WRITE', chunk, encoding)
494
+ return super.write(chunk, encoding, callback)
495
+ }
496
+ end (chunk, encoding, callback) {
497
+ console.log('END', chunk, encoding)
498
+ return super.end(chunk, encoding, callback)
499
+ }
500
+ }
501
+
502
+ someSource.pipe(new Logger()).pipe(someDest)
503
+ ```
504
+
505
+ ### same thing, but using an inline anonymous class
506
+
507
+ ```js
508
+ // js classes are fun
509
+ someSource
510
+ .pipe(new (class extends Minipass {
511
+ emit (ev, ...data) {
512
+ // let's also log events, because debugging some weird thing
513
+ console.log('EMIT', ev)
514
+ return super.emit(ev, ...data)
515
+ }
516
+ write (chunk, encoding, callback) {
517
+ console.log('WRITE', chunk, encoding)
518
+ return super.write(chunk, encoding, callback)
519
+ }
520
+ end (chunk, encoding, callback) {
521
+ console.log('END', chunk, encoding)
522
+ return super.end(chunk, encoding, callback)
523
+ }
524
+ }))
525
+ .pipe(someDest)
526
+ ```
527
+
528
+ ### subclass that defers 'end' for some reason
529
+
530
+ ```js
531
+ class SlowEnd extends Minipass {
532
+ emit (ev, ...args) {
533
+ if (ev === 'end') {
534
+ console.log('going to end, hold on a sec')
535
+ setTimeout(() => {
536
+ console.log('ok, ready to end now')
537
+ super.emit('end', ...args)
538
+ }, 100)
539
+ } else {
540
+ return super.emit(ev, ...args)
541
+ }
542
+ }
543
+ }
544
+ ```
545
+
546
+ ### transform that creates newline-delimited JSON
547
+
548
+ ```js
549
+ class NDJSONEncode extends Minipass {
550
+ write (obj, cb) {
551
+ try {
552
+ // JSON.stringify can throw, emit an error on that
553
+ return super.write(JSON.stringify(obj) + '\n', 'utf8', cb)
554
+ } catch (er) {
555
+ this.emit('error', er)
556
+ }
557
+ }
558
+ end (obj, cb) {
559
+ if (typeof obj === 'function') {
560
+ cb = obj
561
+ obj = undefined
562
+ }
563
+ if (obj !== undefined) {
564
+ this.write(obj)
565
+ }
566
+ return super.end(cb)
567
+ }
568
+ }
569
+ ```
570
+
571
+ ### transform that parses newline-delimited JSON
572
+
573
+ ```js
574
+ class NDJSONDecode extends Minipass {
575
+ constructor (options) {
576
+ // always be in object mode, as far as Minipass is concerned
577
+ super({ objectMode: true })
578
+ this._jsonBuffer = ''
579
+ }
580
+ write (chunk, encoding, cb) {
581
+ if (typeof chunk === 'string' &&
582
+ typeof encoding === 'string' &&
583
+ encoding !== 'utf8') {
584
+ chunk = Buffer.from(chunk, encoding).toString()
585
+ } else if (Buffer.isBuffer(chunk))
586
+ chunk = chunk.toString()
587
+ }
588
+ if (typeof encoding === 'function') {
589
+ cb = encoding
590
+ }
591
+ const jsonData = (this._jsonBuffer + chunk).split('\n')
592
+ this._jsonBuffer = jsonData.pop()
593
+ for (let i = 0; i < jsonData.length; i++) {
594
+ let parsed
595
+ try {
596
+ super.write(parsed)
597
+ } catch (er) {
598
+ this.emit('error', er)
599
+ continue
600
+ }
601
+ }
602
+ if (cb)
603
+ cb()
604
+ }
605
+ }
606
+ ```