Last change
on this file since b738035 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
859 bytes
|
Line | |
---|
1 | # minipass-sized
|
---|
2 |
|
---|
3 | A Minipass stream that raises an error if you get a different number of
|
---|
4 | bytes than expected.
|
---|
5 |
|
---|
6 | ## USAGE
|
---|
7 |
|
---|
8 | Use just like any old [minipass](http://npm.im/minipass) stream, but
|
---|
9 | provide a `size` option to the constructor.
|
---|
10 |
|
---|
11 | The `size` option must be a positive integer, smaller than
|
---|
12 | `Number.MAX_SAFE_INTEGER`.
|
---|
13 |
|
---|
14 | ```js
|
---|
15 | const MinipassSized = require('minipass-sized')
|
---|
16 | // figure out how much data you expect to get
|
---|
17 | const expectedSize = +headers['content-length']
|
---|
18 | const stream = new MinipassSized({ size: expectedSize })
|
---|
19 | stream.on('error', er => {
|
---|
20 | // if it's the wrong size, then this will raise an error with
|
---|
21 | // { found: <number>, expect: <number>, code: 'EBADSIZE' }
|
---|
22 | })
|
---|
23 | response.pipe(stream)
|
---|
24 | ```
|
---|
25 |
|
---|
26 | Caveats: this does not work with `objectMode` streams, and will throw a
|
---|
27 | `TypeError` from the constructor if the size argument is missing or
|
---|
28 | invalid.
|
---|
Note:
See
TracBrowser
for help on using the repository browser.