muhammara 3.6.0 → 3.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -1
- package/README.md +1 -1
- package/lib/recipe/htmlToTextObjects.js +6 -4
- package/node_modules/minipass/LICENSE +1 -1
- package/node_modules/minipass/README.md +127 -123
- package/node_modules/minipass/index.d.ts +2 -2
- package/node_modules/minipass/index.js +233 -224
- package/node_modules/minipass/package.json +9 -9
- package/node_modules/node-fetch/browser.js +1 -1
- package/node_modules/node-fetch/lib/index.es.js +3 -1
- package/node_modules/node-fetch/lib/index.js +3 -1
- package/node_modules/node-fetch/lib/index.mjs +3 -1
- package/node_modules/node-fetch/package.json +5 -5
- package/node_modules/yallist/package.json +0 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,21 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [3.7.0] - 2023-02-09
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Electron 21.4, 22.1 and 22.2
|
|
15
|
+
|
|
16
|
+
### Fixed
|
|
17
|
+
|
|
18
|
+
- Update xmldom to new 0.8.6 and fix security issues
|
|
19
|
+
- Fix arm64 on mac builds
|
|
20
|
+
|
|
21
|
+
### Removed
|
|
22
|
+
|
|
23
|
+
- Pre-builts for macos on arm for node < 15 (eg 14, 12, 10 etc)
|
|
24
|
+
|
|
10
25
|
## [3.6.0] - 2023-01-24
|
|
11
26
|
|
|
12
27
|
### Added
|
|
@@ -343,7 +358,8 @@ with the following changes.
|
|
|
343
358
|
|
|
344
359
|
- Initial release
|
|
345
360
|
|
|
346
|
-
[unreleased]: https://github.com/julianhille/MuhammaraJS/compare/3.
|
|
361
|
+
[unreleased]: https://github.com/julianhille/MuhammaraJS/compare/3.7.0...HEAD
|
|
362
|
+
[3.7.0]: https://github.com/julianhille/MuhammaraJS/compare/3.6.0...3.7.0
|
|
347
363
|
[3.6.0]: https://github.com/julianhille/MuhammaraJS/compare/3.5.0...3.6.0
|
|
348
364
|
[3.5.0]: https://github.com/julianhille/MuhammaraJS/compare/3.4.0...3.5.0
|
|
349
365
|
[3.4.0]: https://github.com/julianhille/MuhammaraJS/compare/3.3.0...3.4.0
|
package/README.md
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
const DOMParser = require("xmldom").DOMParser;
|
|
1
|
+
const DOMParser = require("@xmldom/xmldom").DOMParser;
|
|
2
2
|
|
|
3
3
|
exports.htmlToTextObjects = function (htmlCodes) {
|
|
4
4
|
htmlCodes = htmlCodes.replace(/<br\/?>/g, "<p>[@@DONOT_RENDER_THIS@@]</p>");
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
const nodes = new DOMParser().parseFromString(
|
|
6
|
+
`<html>${htmlCodes}</html>`,
|
|
7
|
+
"text/html"
|
|
8
|
+
);
|
|
9
|
+
const textObjects = parseNode(nodes).childs[0].childs;
|
|
8
10
|
return textObjects;
|
|
9
11
|
};
|
|
10
12
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
The ISC License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2017-
|
|
3
|
+
Copyright (c) 2017-2023 npm, Inc., Isaac Z. Schlueter, and Contributors
|
|
4
4
|
|
|
5
5
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
6
|
purpose with or without fee is hereby granted, provided that the above
|
|
@@ -4,7 +4,7 @@ A _very_ minimal implementation of a [PassThrough
|
|
|
4
4
|
stream](https://nodejs.org/api/stream.html#stream_class_stream_passthrough)
|
|
5
5
|
|
|
6
6
|
[It's very
|
|
7
|
-
fast](https://docs.google.com/spreadsheets/d/
|
|
7
|
+
fast](https://docs.google.com/spreadsheets/d/1K_HR5oh3r80b8WVMWCPPjfuWXUgfkmhlX7FGI6JJ8tY/edit?usp=sharing)
|
|
8
8
|
for objects, strings, and buffers.
|
|
9
9
|
|
|
10
10
|
Supports `pipe()`ing (including multi-`pipe()` and backpressure transmission),
|
|
@@ -14,20 +14,20 @@ a good idea.
|
|
|
14
14
|
|
|
15
15
|
There is a `read()` method, but it's much more efficient to consume data
|
|
16
16
|
from this stream via `'data'` events or by calling `pipe()` into some other
|
|
17
|
-
stream.
|
|
17
|
+
stream. Calling `read()` requires the buffer to be flattened in some
|
|
18
18
|
cases, which requires copying memory.
|
|
19
19
|
|
|
20
20
|
If you set `objectMode: true` in the options, then whatever is written will
|
|
21
|
-
be emitted.
|
|
21
|
+
be emitted. Otherwise, it'll do a minimal amount of Buffer copying to
|
|
22
22
|
ensure proper Streams semantics when `read(n)` is called.
|
|
23
23
|
|
|
24
24
|
`objectMode` can also be set by doing `stream.objectMode = true`, or by
|
|
25
|
-
writing any non-string/non-buffer data.
|
|
25
|
+
writing any non-string/non-buffer data. `objectMode` cannot be set to
|
|
26
26
|
false once it is set.
|
|
27
27
|
|
|
28
|
-
This is not a `through` or `through2` stream.
|
|
29
|
-
data, it just passes it right through.
|
|
30
|
-
extend the class, and override the `write()` method.
|
|
28
|
+
This is not a `through` or `through2` stream. It doesn't transform the
|
|
29
|
+
data, it just passes it right through. If you want to transform the data,
|
|
30
|
+
extend the class, and override the `write()` method. Once you're done
|
|
31
31
|
transforming the data however you want, call `super.write()` with the
|
|
32
32
|
transform output.
|
|
33
33
|
|
|
@@ -66,9 +66,9 @@ constructor options.
|
|
|
66
66
|
|
|
67
67
|
### Timing
|
|
68
68
|
|
|
69
|
-
Minipass streams are designed to support synchronous use-cases.
|
|
70
|
-
is emitted as soon as it is available, always.
|
|
71
|
-
but no longer.
|
|
69
|
+
Minipass streams are designed to support synchronous use-cases. Thus, data
|
|
70
|
+
is emitted as soon as it is available, always. It is buffered until read,
|
|
71
|
+
but no longer. Another way to look at it is that Minipass streams are
|
|
72
72
|
exactly as synchronous as the logic that writes into them.
|
|
73
73
|
|
|
74
74
|
This can be surprising if your code relies on `PassThrough.write()` always
|
|
@@ -77,7 +77,7 @@ to call `resume()` and not have the entire buffer disappear immediately.
|
|
|
77
77
|
|
|
78
78
|
However, without this synchronicity guarantee, there would be no way for
|
|
79
79
|
Minipass to achieve the speeds it does, or support the synchronous use
|
|
80
|
-
cases that it does.
|
|
80
|
+
cases that it does. Simply put, waiting takes time.
|
|
81
81
|
|
|
82
82
|
This non-deferring approach makes Minipass streams much easier to reason
|
|
83
83
|
about, especially in the context of Promises and other flow-control
|
|
@@ -87,7 +87,7 @@ Example:
|
|
|
87
87
|
|
|
88
88
|
```js
|
|
89
89
|
const Minipass = require('minipass')
|
|
90
|
-
const stream = new Minipass(
|
|
90
|
+
const stream = new Minipass()
|
|
91
91
|
stream.on('data', () => console.log('data event'))
|
|
92
92
|
console.log('before write')
|
|
93
93
|
stream.write('hello')
|
|
@@ -119,7 +119,7 @@ console.log('after write')
|
|
|
119
119
|
```
|
|
120
120
|
|
|
121
121
|
Switching _out_ of async mode is unsafe, as it could cause data
|
|
122
|
-
corruption, and so is not enabled.
|
|
122
|
+
corruption, and so is not enabled. Example:
|
|
123
123
|
|
|
124
124
|
```js
|
|
125
125
|
const Minipass = require('minipass')
|
|
@@ -166,7 +166,7 @@ on all writes until the limit is hit, even if the data has nowhere to go.
|
|
|
166
166
|
Then, they will not attempt to draw more data in until the buffer size dips
|
|
167
167
|
below a minimum value.
|
|
168
168
|
|
|
169
|
-
Minipass streams are much simpler.
|
|
169
|
+
Minipass streams are much simpler. The `write()` method will return `true`
|
|
170
170
|
if the data has somewhere to go (which is to say, given the timing
|
|
171
171
|
guarantees, that the data is already there by the time `write()` returns).
|
|
172
172
|
|
|
@@ -182,12 +182,12 @@ copying data, and less bookkeeping about buffer capacity levels.
|
|
|
182
182
|
Since data written to a Minipass stream is immediately written all the way
|
|
183
183
|
through the pipeline, and `write()` always returns true/false based on
|
|
184
184
|
whether the data was fully flushed, backpressure is communicated
|
|
185
|
-
immediately to the upstream caller.
|
|
185
|
+
immediately to the upstream caller. This minimizes buffering.
|
|
186
186
|
|
|
187
187
|
Consider this case:
|
|
188
188
|
|
|
189
189
|
```js
|
|
190
|
-
const {PassThrough} = require('stream')
|
|
190
|
+
const { PassThrough } = require('stream')
|
|
191
191
|
const p1 = new PassThrough({ highWaterMark: 1024 })
|
|
192
192
|
const p2 = new PassThrough({ highWaterMark: 1024 })
|
|
193
193
|
const p3 = new PassThrough({ highWaterMark: 1024 })
|
|
@@ -216,7 +216,7 @@ perfectly safe to write all the way through!
|
|
|
216
216
|
|
|
217
217
|
Furthermore, setting a `highWaterMark` of `1024` might lead someone reading
|
|
218
218
|
the code to think an advisory maximum of 1KiB is being set for the
|
|
219
|
-
pipeline.
|
|
219
|
+
pipeline. However, the actual advisory buffering level is the _sum_ of
|
|
220
220
|
`highWaterMark` values, since each one has its own bucket.
|
|
221
221
|
|
|
222
222
|
Consider the Minipass case:
|
|
@@ -243,7 +243,7 @@ m1.write(Buffer.alloc(2048)) // returns true
|
|
|
243
243
|
```
|
|
244
244
|
|
|
245
245
|
It is extremely unlikely that you _don't_ want to buffer any data written,
|
|
246
|
-
or _ever_ buffer data that can be flushed all the way through.
|
|
246
|
+
or _ever_ buffer data that can be flushed all the way through. Neither
|
|
247
247
|
node-core streams nor Minipass ever fail to buffer written data, but
|
|
248
248
|
node-core streams do a lot of unnecessary buffering and pausing.
|
|
249
249
|
|
|
@@ -266,12 +266,12 @@ However, this is _usually_ not a problem because:
|
|
|
266
266
|
### Emit `end` When Asked
|
|
267
267
|
|
|
268
268
|
One hazard of immediately emitting `'end'` is that you may not yet have had
|
|
269
|
-
a chance to add a listener.
|
|
269
|
+
a chance to add a listener. In order to avoid this hazard, Minipass
|
|
270
270
|
streams safely re-emit the `'end'` event if a new listener is added after
|
|
271
271
|
`'end'` has been emitted.
|
|
272
272
|
|
|
273
273
|
Ie, if you do `stream.on('end', someFunction)`, and the stream has already
|
|
274
|
-
emitted `end`, then it will call the handler right away.
|
|
274
|
+
emitted `end`, then it will call the handler right away. (You can think of
|
|
275
275
|
this somewhat like attaching a new `.then(fn)` to a previously-resolved
|
|
276
276
|
Promise.)
|
|
277
277
|
|
|
@@ -282,7 +282,7 @@ is emitted.
|
|
|
282
282
|
### Emit `error` When Asked
|
|
283
283
|
|
|
284
284
|
The most recent error object passed to the `'error'` event is
|
|
285
|
-
stored on the stream.
|
|
285
|
+
stored on the stream. If a new `'error'` event handler is added,
|
|
286
286
|
and an error was previously emitted, then the event handler will
|
|
287
287
|
be called immediately (or on `process.nextTick` in the case of
|
|
288
288
|
async streams).
|
|
@@ -328,7 +328,7 @@ tee.pipe(dest2)
|
|
|
328
328
|
src.pipe(tee) // tee gets 'foo', pipes to both locations
|
|
329
329
|
```
|
|
330
330
|
|
|
331
|
-
The same caveat applies to `on('data')` event listeners.
|
|
331
|
+
The same caveat applies to `on('data')` event listeners. The first one
|
|
332
332
|
added will _immediately_ receive all of the data, leaving nothing for the
|
|
333
333
|
second:
|
|
334
334
|
|
|
@@ -354,14 +354,14 @@ src.pipe(tee)
|
|
|
354
354
|
|
|
355
355
|
All of the hazards in this section are avoided by setting `{
|
|
356
356
|
async: true }` in the Minipass constructor, or by setting
|
|
357
|
-
`stream.async = true` afterwards.
|
|
357
|
+
`stream.async = true` afterwards. Note that this does add some
|
|
358
358
|
overhead, so should only be done in cases where you are willing
|
|
359
359
|
to lose a bit of performance in order to avoid having to refactor
|
|
360
360
|
program logic.
|
|
361
361
|
|
|
362
362
|
## USAGE
|
|
363
363
|
|
|
364
|
-
It's a stream!
|
|
364
|
+
It's a stream! Use it like a stream and it'll most likely do what you
|
|
365
365
|
want.
|
|
366
366
|
|
|
367
367
|
```js
|
|
@@ -374,16 +374,16 @@ mp.end('bar')
|
|
|
374
374
|
|
|
375
375
|
### OPTIONS
|
|
376
376
|
|
|
377
|
-
|
|
378
|
-
encoded?
|
|
379
|
-
|
|
377
|
+
- `encoding` How would you like the data coming _out_ of the stream to be
|
|
378
|
+
encoded? Accepts any values that can be passed to `Buffer.toString()`.
|
|
379
|
+
- `objectMode` Emit data exactly as it comes in. This will be flipped on
|
|
380
380
|
by default if you write() something other than a string or Buffer at any
|
|
381
|
-
point.
|
|
381
|
+
point. Setting `objectMode: true` will prevent setting any encoding
|
|
382
382
|
value.
|
|
383
|
-
|
|
384
|
-
emission until next tick.
|
|
383
|
+
- `async` Defaults to `false`. Set to `true` to defer data
|
|
384
|
+
emission until next tick. This reduces performance slightly,
|
|
385
385
|
but makes Minipass streams use timing behavior closer to Node
|
|
386
|
-
core streams.
|
|
386
|
+
core streams. See [Timing](#timing) for more details.
|
|
387
387
|
|
|
388
388
|
### API
|
|
389
389
|
|
|
@@ -392,113 +392,113 @@ streams.
|
|
|
392
392
|
|
|
393
393
|
### Methods
|
|
394
394
|
|
|
395
|
-
|
|
396
|
-
base Minipass class, the same data will come out.)
|
|
395
|
+
- `write(chunk, [encoding], [callback])` - Put data in. (Note that, in the
|
|
396
|
+
base Minipass class, the same data will come out.) Returns `false` if
|
|
397
397
|
the stream will buffer the next write, or true if it's still in "flowing"
|
|
398
398
|
mode.
|
|
399
|
-
|
|
400
|
-
data to write.
|
|
399
|
+
- `end([chunk, [encoding]], [callback])` - Signal that you have no more
|
|
400
|
+
data to write. This will queue an `end` event to be fired when all the
|
|
401
401
|
data has been consumed.
|
|
402
|
-
|
|
402
|
+
- `setEncoding(encoding)` - Set the encoding for data coming of the stream.
|
|
403
403
|
This can only be done once.
|
|
404
|
-
|
|
404
|
+
- `pause()` - No more data for a while, please. This also prevents `end`
|
|
405
405
|
from being emitted for empty streams until the stream is resumed.
|
|
406
|
-
|
|
407
|
-
discarded.
|
|
408
|
-
|
|
406
|
+
- `resume()` - Resume the stream. If there's data in the buffer, it is all
|
|
407
|
+
discarded. Any buffered events are immediately emitted.
|
|
408
|
+
- `pipe(dest)` - Send all output to the stream provided. When
|
|
409
409
|
data is emitted, it is immediately written to any and all pipe
|
|
410
|
-
destinations.
|
|
411
|
-
|
|
410
|
+
destinations. (Or written on next tick in `async` mode.)
|
|
411
|
+
- `unpipe(dest)` - Stop piping to the destination stream. This
|
|
412
412
|
is immediate, meaning that any asynchronously queued data will
|
|
413
413
|
_not_ make it to the destination when running in `async` mode.
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
events are given special treatment, however.
|
|
423
|
-
|
|
414
|
+
- `options.end` - Boolean, end the destination stream when
|
|
415
|
+
the source stream ends. Default `true`.
|
|
416
|
+
- `options.proxyErrors` - Boolean, proxy `error` events from
|
|
417
|
+
the source stream to the destination stream. Note that
|
|
418
|
+
errors are _not_ proxied after the pipeline terminates,
|
|
419
|
+
either due to the source emitting `'end'` or manually
|
|
420
|
+
unpiping with `src.unpipe(dest)`. Default `false`.
|
|
421
|
+
- `on(ev, fn)`, `emit(ev, fn)` - Minipass streams are EventEmitters. Some
|
|
422
|
+
events are given special treatment, however. (See below under "events".)
|
|
423
|
+
- `promise()` - Returns a Promise that resolves when the stream emits
|
|
424
424
|
`end`, or rejects if the stream emits `error`.
|
|
425
|
-
|
|
425
|
+
- `collect()` - Return a Promise that resolves on `end` with an array
|
|
426
426
|
containing each chunk of data that was emitted, or rejects if the stream
|
|
427
|
-
emits `error`.
|
|
428
|
-
|
|
429
|
-
Buffer object.
|
|
427
|
+
emits `error`. Note that this consumes the stream data.
|
|
428
|
+
- `concat()` - Same as `collect()`, but concatenates the data into a single
|
|
429
|
+
Buffer object. Will reject the returned promise if the stream is in
|
|
430
430
|
objectMode, or if it goes into objectMode by the end of the data.
|
|
431
|
-
|
|
432
|
-
provided, then consume all of it.
|
|
433
|
-
it returns null.
|
|
431
|
+
- `read(n)` - Consume `n` bytes of data out of the buffer. If `n` is not
|
|
432
|
+
provided, then consume all of it. If `n` bytes are not available, then
|
|
433
|
+
it returns null. **Note** consuming streams in this way is less
|
|
434
434
|
efficient, and can lead to unnecessary Buffer copying.
|
|
435
|
-
|
|
436
|
-
`'error'` event is emitted.
|
|
435
|
+
- `destroy([er])` - Destroy the stream. If an error is provided, then an
|
|
436
|
+
`'error'` event is emitted. If the stream has a `close()` method, and
|
|
437
437
|
has not emitted a `'close'` event yet, then `stream.close()` will be
|
|
438
|
-
called.
|
|
439
|
-
`.concat()` will be rejected.
|
|
440
|
-
stream will emit an error.
|
|
438
|
+
called. Any Promises returned by `.promise()`, `.collect()` or
|
|
439
|
+
`.concat()` will be rejected. After being destroyed, writing to the
|
|
440
|
+
stream will emit an error. No more data will be emitted if the stream is
|
|
441
441
|
destroyed, even if it was previously buffered.
|
|
442
442
|
|
|
443
443
|
### Properties
|
|
444
444
|
|
|
445
|
-
|
|
445
|
+
- `bufferLength` Read-only. Total number of bytes buffered, or in the case
|
|
446
446
|
of objectMode, the total number of objects.
|
|
447
|
-
|
|
447
|
+
- `encoding` The encoding that has been set. (Setting this is equivalent
|
|
448
448
|
to calling `setEncoding(enc)` and has the same prohibition against
|
|
449
449
|
setting multiple times.)
|
|
450
|
-
|
|
450
|
+
- `flowing` Read-only. Boolean indicating whether a chunk written to the
|
|
451
451
|
stream will be immediately emitted.
|
|
452
|
-
|
|
453
|
-
(ie, `end`, `prefinish`, `finish`) have been emitted.
|
|
452
|
+
- `emittedEnd` Read-only. Boolean indicating whether the end-ish events
|
|
453
|
+
(ie, `end`, `prefinish`, `finish`) have been emitted. Note that
|
|
454
454
|
listening on any end-ish event will immediateyl re-emit it if it has
|
|
455
455
|
already been emitted.
|
|
456
|
-
|
|
456
|
+
- `writable` Whether the stream is writable. Default `true`. Set to
|
|
457
457
|
`false` when `end()`
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
to the stream that have not yet been emitted.
|
|
458
|
+
- `readable` Whether the stream is readable. Default `true`.
|
|
459
|
+
- `buffer` A [yallist](http://npm.im/yallist) linked list of chunks written
|
|
460
|
+
to the stream that have not yet been emitted. (It's probably a bad idea
|
|
461
461
|
to mess with this.)
|
|
462
|
-
|
|
463
|
-
this stream is piping into.
|
|
462
|
+
- `pipes` A [yallist](http://npm.im/yallist) linked list of streams that
|
|
463
|
+
this stream is piping into. (It's probably a bad idea to mess with
|
|
464
464
|
this.)
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
465
|
+
- `destroyed` A getter that indicates whether the stream was destroyed.
|
|
466
|
+
- `paused` True if the stream has been explicitly paused, otherwise false.
|
|
467
|
+
- `objectMode` Indicates whether the stream is in `objectMode`. Once set
|
|
468
468
|
to `true`, it cannot be set to `false`.
|
|
469
469
|
|
|
470
470
|
### Events
|
|
471
471
|
|
|
472
|
-
|
|
473
|
-
This is never emitted while not flowing.
|
|
472
|
+
- `data` Emitted when there's data to read. Argument is the data to read.
|
|
473
|
+
This is never emitted while not flowing. If a listener is attached, that
|
|
474
474
|
will resume the stream.
|
|
475
|
-
|
|
476
|
-
immediately for empty streams when `end()` is called.
|
|
475
|
+
- `end` Emitted when there's no more data to read. This will be emitted
|
|
476
|
+
immediately for empty streams when `end()` is called. If a listener is
|
|
477
477
|
attached, and `end` was already emitted, then it will be emitted again.
|
|
478
478
|
All listeners are removed when `end` is emitted.
|
|
479
|
-
|
|
480
|
-
emitted in the same conditions where `end` is emitted.
|
|
479
|
+
- `prefinish` An end-ish event that follows the same logic as `end` and is
|
|
480
|
+
emitted in the same conditions where `end` is emitted. Emitted after
|
|
481
481
|
`'end'`.
|
|
482
|
-
|
|
483
|
-
emitted in the same conditions where `end` is emitted.
|
|
482
|
+
- `finish` An end-ish event that follows the same logic as `end` and is
|
|
483
|
+
emitted in the same conditions where `end` is emitted. Emitted after
|
|
484
484
|
`'prefinish'`.
|
|
485
|
-
|
|
485
|
+
- `close` An indication that an underlying resource has been released.
|
|
486
486
|
Minipass does not emit this event, but will defer it until after `end`
|
|
487
487
|
has been emitted, since it throws off some stream libraries otherwise.
|
|
488
|
-
|
|
488
|
+
- `drain` Emitted when the internal buffer empties, and it is again
|
|
489
489
|
suitable to `write()` into the stream.
|
|
490
|
-
|
|
490
|
+
- `readable` Emitted when data is buffered and ready to be read by a
|
|
491
491
|
consumer.
|
|
492
|
-
|
|
493
|
-
mode.
|
|
492
|
+
- `resume` Emitted when stream changes state from buffering to flowing
|
|
493
|
+
mode. (Ie, when `resume` is called, `pipe` is called, or a `data` event
|
|
494
494
|
listener is added.)
|
|
495
495
|
|
|
496
496
|
### Static Methods
|
|
497
497
|
|
|
498
|
-
|
|
499
|
-
and false otherwise.
|
|
498
|
+
- `Minipass.isStream(stream)` Returns `true` if the argument is a stream,
|
|
499
|
+
and false otherwise. To be considered a stream, the object must be
|
|
500
500
|
either an instance of Minipass, or an EventEmitter that has either a
|
|
501
|
-
`pipe()` method, or both `write()` and `end()` methods.
|
|
501
|
+
`pipe()` method, or both `write()` and `end()` methods. (Pretty much any
|
|
502
502
|
stream in node-land will return `true` for this.)
|
|
503
503
|
|
|
504
504
|
## EXAMPLES
|
|
@@ -508,11 +508,14 @@ Here are some examples of things you can do with Minipass streams.
|
|
|
508
508
|
### simple "are you done yet" promise
|
|
509
509
|
|
|
510
510
|
```js
|
|
511
|
-
mp.promise().then(
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
511
|
+
mp.promise().then(
|
|
512
|
+
() => {
|
|
513
|
+
// stream is finished
|
|
514
|
+
},
|
|
515
|
+
er => {
|
|
516
|
+
// stream emitted an error
|
|
517
|
+
}
|
|
518
|
+
)
|
|
516
519
|
```
|
|
517
520
|
|
|
518
521
|
### collecting
|
|
@@ -548,7 +551,7 @@ You can iterate over streams synchronously or asynchronously in platforms
|
|
|
548
551
|
that support it.
|
|
549
552
|
|
|
550
553
|
Synchronous iteration will end when the currently available data is
|
|
551
|
-
consumed, even if the `end` event has not been reached.
|
|
554
|
+
consumed, even if the `end` event has not been reached. In string and
|
|
552
555
|
buffer mode, the data is concatenated, so unless multiple writes are
|
|
553
556
|
occurring in the same tick as the `read()`, sync iteration loops will
|
|
554
557
|
generally only have a single iteration.
|
|
@@ -587,8 +590,7 @@ const mp = new Minipass({ encoding: 'utf8' })
|
|
|
587
590
|
// some source of some data
|
|
588
591
|
let i = 5
|
|
589
592
|
const inter = setInterval(() => {
|
|
590
|
-
if (i-- > 0)
|
|
591
|
-
mp.write(Buffer.from('foo\n', 'utf8'))
|
|
593
|
+
if (i-- > 0) mp.write(Buffer.from('foo\n', 'utf8'))
|
|
592
594
|
else {
|
|
593
595
|
mp.end()
|
|
594
596
|
clearInterval(inter)
|
|
@@ -596,7 +598,7 @@ const inter = setInterval(() => {
|
|
|
596
598
|
}, 100)
|
|
597
599
|
|
|
598
600
|
// consume the data with asynchronous iteration
|
|
599
|
-
async function consume
|
|
601
|
+
async function consume() {
|
|
600
602
|
for await (let chunk of mp) {
|
|
601
603
|
console.log(chunk)
|
|
602
604
|
}
|
|
@@ -611,11 +613,11 @@ consume().then(res => console.log(res))
|
|
|
611
613
|
|
|
612
614
|
```js
|
|
613
615
|
class Logger extends Minipass {
|
|
614
|
-
write
|
|
616
|
+
write(chunk, encoding, callback) {
|
|
615
617
|
console.log('WRITE', chunk, encoding)
|
|
616
618
|
return super.write(chunk, encoding, callback)
|
|
617
619
|
}
|
|
618
|
-
end
|
|
620
|
+
end(chunk, encoding, callback) {
|
|
619
621
|
console.log('END', chunk, encoding)
|
|
620
622
|
return super.end(chunk, encoding, callback)
|
|
621
623
|
}
|
|
@@ -629,21 +631,23 @@ someSource.pipe(new Logger()).pipe(someDest)
|
|
|
629
631
|
```js
|
|
630
632
|
// js classes are fun
|
|
631
633
|
someSource
|
|
632
|
-
.pipe(
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
634
|
+
.pipe(
|
|
635
|
+
new (class extends Minipass {
|
|
636
|
+
emit(ev, ...data) {
|
|
637
|
+
// let's also log events, because debugging some weird thing
|
|
638
|
+
console.log('EMIT', ev)
|
|
639
|
+
return super.emit(ev, ...data)
|
|
640
|
+
}
|
|
641
|
+
write(chunk, encoding, callback) {
|
|
642
|
+
console.log('WRITE', chunk, encoding)
|
|
643
|
+
return super.write(chunk, encoding, callback)
|
|
644
|
+
}
|
|
645
|
+
end(chunk, encoding, callback) {
|
|
646
|
+
console.log('END', chunk, encoding)
|
|
647
|
+
return super.end(chunk, encoding, callback)
|
|
648
|
+
}
|
|
649
|
+
})()
|
|
650
|
+
)
|
|
647
651
|
.pipe(someDest)
|
|
648
652
|
```
|
|
649
653
|
|
|
@@ -651,7 +655,7 @@ someSource
|
|
|
651
655
|
|
|
652
656
|
```js
|
|
653
657
|
class SlowEnd extends Minipass {
|
|
654
|
-
emit
|
|
658
|
+
emit(ev, ...args) {
|
|
655
659
|
if (ev === 'end') {
|
|
656
660
|
console.log('going to end, hold on a sec')
|
|
657
661
|
setTimeout(() => {
|
|
@@ -669,7 +673,7 @@ class SlowEnd extends Minipass {
|
|
|
669
673
|
|
|
670
674
|
```js
|
|
671
675
|
class NDJSONEncode extends Minipass {
|
|
672
|
-
write
|
|
676
|
+
write(obj, cb) {
|
|
673
677
|
try {
|
|
674
678
|
// JSON.stringify can throw, emit an error on that
|
|
675
679
|
return super.write(JSON.stringify(obj) + '\n', 'utf8', cb)
|
|
@@ -677,7 +681,7 @@ class NDJSONEncode extends Minipass {
|
|
|
677
681
|
this.emit('error', er)
|
|
678
682
|
}
|
|
679
683
|
}
|
|
680
|
-
end
|
|
684
|
+
end(obj, cb) {
|
|
681
685
|
if (typeof obj === 'function') {
|
|
682
686
|
cb = obj
|
|
683
687
|
obj = undefined
|
|
@@ -140,8 +140,8 @@ declare class Minipass<
|
|
|
140
140
|
listener: () => any
|
|
141
141
|
): this
|
|
142
142
|
|
|
143
|
-
[Symbol.iterator]():
|
|
144
|
-
[Symbol.asyncIterator]():
|
|
143
|
+
[Symbol.iterator](): Generator<RType, void, void>
|
|
144
|
+
[Symbol.asyncIterator](): AsyncGenerator<RType, void, void>
|
|
145
145
|
}
|
|
146
146
|
|
|
147
147
|
export = Minipass
|