0.3.5 • Published 10 years ago

chopshop v0.3.5

Weekly downloads
3
License
ISC
Repository
github
Last release
10 years ago

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.

0.3.5

10 years ago

0.3.4

10 years ago

0.3.3

10 years ago

0.3.2

10 years ago

0.3.1

10 years ago

0.3.0

10 years ago

0.2.4

10 years ago

0.2.3

10 years ago

0.2.2

10 years ago

0.2.1

10 years ago

0.2.0

10 years ago

0.1.6

10 years ago

0.1.5

10 years ago

0.1.4

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago