wecui
Version:
一款基于Vue2.x版本的移动端web组件
63 lines (38 loc) • 1.56 kB
Markdown
in a stream
Useful if you want to do something to the first chunk.
You can also set the minimum size of that chunk.
```sh
$ npm install --save first-chunk-stream
```
```js
var fs = require('fs');
var concat = require('concat-stream');
var firstChunk = require('first-chunk-stream');
// unicorn.txt => unicorn rainbow
// `highWaterMark: 1` means it will only read 1 byte at the time
fs.createReadStream('unicorn.txt', {highWaterMark: 1})
.pipe(firstChunk({minSize: 7}, function (chunk, enc, cb) {
this.push(chunk.toUpperCase());
cb();
}))
.pipe(concat(function (data) {
console.log(data);
//=> UNICORN rainbow
}));
```
Type: `number`
The minimum size of the first chunk.
*Required*
Type: `function`
The [function](http://nodejs.org/docs/latest/api/stream.html#stream_transform_transform_chunk_encoding_callback) that gets the first chunk.
Instead of returning a [stream.Transform](http://nodejs.org/docs/latest/api/stream.html#stream_class_stream_transform_1) instance, `firstChunk.ctor()` returns a constructor for a custom Transform. This is useful when you want to use the same transform logic in multiple instances.
MIT © [Sindre Sorhus](http://sindresorhus.com)
> Transform the first chunk