Initial commit
[yaffs-website] / node_modules / first-chunk-stream / readme.md
1 # first-chunk-stream [![Build Status](https://travis-ci.org/sindresorhus/first-chunk-stream.svg?branch=master)](https://travis-ci.org/sindresorhus/first-chunk-stream)
2
3 > Transform the first chunk in a stream
4
5 Useful if you want to do something to the first chunk.
6
7 You can also set the minimum size of that chunk.
8
9
10 ## Install
11
12 ```sh
13 $ npm install --save first-chunk-stream
14 ```
15
16
17 ## Usage
18
19 ```js
20 var fs = require('fs');
21 var concat = require('concat-stream');
22 var firstChunk = require('first-chunk-stream');
23
24 // unicorn.txt => unicorn rainbow
25 // `highWaterMark: 1` means it will only read 1 byte at the time
26 fs.createReadStream('unicorn.txt', {highWaterMark: 1})
27         .pipe(firstChunk({minSize: 7}, function (chunk, enc, cb) {
28                 this.push(chunk.toUpperCase());
29                 cb();
30         }))
31         .pipe(concat(function (data) {
32                 console.log(data);
33                 //=> UNICORN rainbow
34         }));
35 ```
36
37
38 ## API
39
40 ### firstChunk([options], transform)
41
42 #### options.minSize
43
44 Type: `number`
45
46 The minimum size of the first chunk.
47
48 #### transform(chunk, encoding, callback)
49
50 *Required*  
51 Type: `function`
52
53 The [function](http://nodejs.org/docs/latest/api/stream.html#stream_transform_transform_chunk_encoding_callback) that gets the first chunk.
54
55 ### firstChunk.ctor()
56
57 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.
58
59
60 ## License
61
62 MIT © [Sindre Sorhus](http://sindresorhus.com)