Socket
Socket
Sign inDemoInstall

first-chunk-stream

Package Overview
Dependencies
0
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    first-chunk-stream

Transform the first chunk in a stream


Version published
Maintainers
1
Install size
4.84 kB
Created

Readme

Source

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

Keywords

FAQs

Last updated on 25 May 2014

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc