Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

chopshop

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chopshop

Chunks a node readable stream into multiple fixed-length streams

  • 0.3.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

chopshop

NPM version Build status

chopshop takes a node readable stream and yields a series of fixed-length streams. This is particularly useful if you need to convert a file into multiple files of size N.

Install

In your project, run:

npm install chopshop --save

or install from the GitHub repo:

npm install ludios/chopshop --save

API

const chunk = require('chopshop').chunk;
chunk(readableStream, maxBytes);

chunk returns an iterable of readable streams, all maxBytes in size except for the last chunk, which may be smaller. You must finish reading a chunk before you start reading the next chunk. If your input stream has 0 bytes, you still get one chunk with 0 bytes.

Example

"use strict";

const chunk = require('chopshop').chunk;
const fs = require('fs');
const co = require('co');

co(function*() {
	for(const chunkStream of chunk(fs.createReadStream('/etc/passwd'), 100)) {
		chunkStream.on('data', function(data) {
			process.stdout.write(data);
			console.log("\n" + data.length + "\n");
		});
		yield new Promise(function(resolve) {
			chunkStream.on('end', resolve);
		});
	}
}).catch(function(e) {
	console.error(e.stack);
});

Be careful: you must not start reading from the next chunk before you finish reading from the current chunk. That's why we use co and a Promise above to wait for the chunk to finish.

Keywords

FAQs

Package last updated on 09 Sep 2015

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc