Transform the first chunk in a stream
Useful if you want to do something to the first chunk.
You can also set the minimum size of that chunk.
$ npm install --save first-chunk-stream
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 that gets the first chunk.
Instead of returning a stream.Transform 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
# first-chunk-stream [![Build Status](https://travis-ci.org/sindresorhus/first-chunk-stream.svg?branch=master)](https://travis-ci.org/sindresorhus/first-chunk-stream) > Transform the first chunk in a stream Useful if you want to do something to the first chunk. You can also set the minimum size of that chunk. ## Install ```sh $ npm install --save first-chunk-stream ``` ## Usage ```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 })); ``` ## API ### firstChunk([options], transform) #### options.minSize Type: `number` The minimum size of the first chunk. #### transform(chunk, encoding, callback) *Required* Type: `function` The [function](http://nodejs.org/docs/latest/api/stream.html#stream_transform_transform_chunk_encoding_callback) that gets the first chunk. ### firstChunk.ctor() 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. ## License MIT © [Sindre Sorhus](http://sindresorhus.com)
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 19553 | swellard | Move and rename clients | ||
//guest/perforce_software/helix-web-services/main/source/clients/2016.1.0/javascript/node_modules/first-chunk-stream/readme.md | |||||
#1 | 18810 | tjuricek |
First-pass at JavaScript client SDK. JavaScript requires Node with Gulp to "browserfy" the library. It's the easiest way I found to use the swagger-js project; bundle up a wrapping method. There is no JavaScript reference guide. The swagger-js doesn't really document what they do very well, actually. Overall I'm not particularly impressed by swagger-js, it was hard to even figure out what the right method syntax was. We may want to invest time in doing it better. This required setting CORS response headers, which are currently defaulted to a fairly insecure setting. |