1
0
Fork 0
management/front/dkha-web-sz-main/node_modules/first-chunk-stream
詹力 1a19ec897f 删除无关模块 2024-01-16 21:26:16 +08:00
..
index.js i4 2023-12-18 13:12:25 +08:00
package.json 删除无关模块 2024-01-16 21:26:16 +08:00
readme.md i4 2023-12-18 13:12:25 +08:00

readme.md

first-chunk-stream Build Status

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

$ npm install --save first-chunk-stream

Usage

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 that gets the first chunk.

firstChunk.ctor()

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.

License

MIT © Sindre Sorhus