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)
3 > Transform the first chunk in a stream
5 Useful if you want to do something to the first chunk.
7 You can also set the minimum size of that chunk.
13 $ npm install --save first-chunk-stream
20 var fs = require('fs');
21 var concat = require('concat-stream');
22 var firstChunk = require('first-chunk-stream');
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());
31 .pipe(concat(function (data) {
40 ### firstChunk([options], transform)
46 The minimum size of the first chunk.
48 #### transform(chunk, encoding, callback)
53 The [function](http://nodejs.org/docs/latest/api/stream.html#stream_transform_transform_chunk_encoding_callback) that gets the first chunk.
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.
62 MIT © [Sindre Sorhus](http://sindresorhus.com)