Socket
Socket
Sign inDemoInstall

chunkit

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chunkit - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

32

index.js

@@ -23,2 +23,3 @@ var EventEmitter = require('events').EventEmitter,

self.reading = false;
self.finished = false;
self.failed = true;

@@ -56,7 +57,6 @@

// Stats
this.stats = {totalBytes: 0, chunks: 0};
this.stats = {bytes: 0, chunks: 0};
// Chunking and buffering
this.buffer = new Buffer(0);
this.chunks = [];

@@ -88,3 +88,3 @@ this.cb = cb;

if (typeof chunk === 'string') chunk = new Buffer(chunk, 'utf-8');
self.stats.totalBytes += chunk.length;
self.stats.bytes += chunk.length;
self.buffer = Buffer.concat([self.buffer, chunk]);

@@ -102,3 +102,3 @@ if (self.buffer.length >= self.options.bytes) {

self.reading = false;
self.flushChunk(function (e) {
self.flushChunk(true, function (e) {
if (e) return self.emit('error', e);

@@ -111,11 +111,15 @@ self.finished = true;

self.initiated = true;
self.stream.on('error', self.streamErrorHandler);
self.stream.on('data', self.streamDataHandler);
self.stream.on('end', self.streamEndHandler);
self.stream.resume();
this.initiated = true;
this.stream.on('error', this.streamErrorHandler);
this.stream.on('data', this.streamDataHandler);
this.stream.on('end', this.streamEndHandler);
this.stream.resume();
}
ChunkIt.prototype.flushChunk = function(cb) {
if (!this.initiated) return;
ChunkIt.prototype.flushChunk = function(last, cb) {
if (!this.initiated || this.finished) return cb();
if (typeof last == 'function') {
cb = last;
last = false;
}

@@ -134,3 +138,3 @@ var self = this;

this.buffer = this.buffer.slice(this.options.bytes);
newChunk.last = !this.reading;
newChunk.last = last;
}

@@ -142,3 +146,3 @@ newChunk.index = ++this.stats.chunks;

// Last chunk
if (!this.reading && this.buffer.length) {
if (!this.reading && last && this.buffer.length) {
newChunk.data = this.buffer.slice(0, this.options.bytes);

@@ -156,3 +160,3 @@ this.buffer = this.buffer.slice(this.options.bytes);

}, function (e) {
if (e) return self.emit('error', e);
if (e) return cb(e);
cb();

@@ -159,0 +163,0 @@ });

@@ -9,3 +9,3 @@ {

"description": "A simple and lightweight interface for chunking stream data in NodeJS",
"version": "0.0.1",
"version": "0.0.2",
"keywords": [

@@ -12,0 +12,0 @@ "chunk stream",

@@ -16,2 +16,3 @@ # Chunk It

* Nothing hits the disk
* Tested with filesizes ranging from 256 bytes to 2GB.

@@ -29,6 +30,6 @@

### Example 1: Callback for 1MB chunks from a readable stream.
### Example 1: Using callback for 1MB chunks
```js
var chunkit = require('chunked-stream'),
var chunkit = require('chunkit'),
fs = require('fs');

@@ -49,3 +50,3 @@

```js
var chunkit = require('chunked-stream'),
var chunkit = require('chunkit'),
fs = require('fs');

@@ -85,5 +86,11 @@

## Stats Object
* **bytes (Integer)** - Total bytes chunked.
* **chunks (Integer)** - Total number of chunks.
## History
* v0.0.2 (2014-04-03) -- Added new examples and features.
* v0.0.1 (2014-04-03) -- Initial release.

@@ -90,0 +97,0 @@

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