Comparing version 0.5.2 to 0.5.3
@@ -44,21 +44,5 @@ var extended = require("../extended"), | ||
var origOn = ParserStream.prototype.on, | ||
origPause = ParserStream.prototype.pause, | ||
origResume = ParserStream.prototype.resume, | ||
origEmit = ParserStream.prototype.emit; | ||
function pause() { | ||
spreadArgs(origPause, arguments, this); | ||
this.paused = true; | ||
this.pause = pause; | ||
} | ||
function resume() { | ||
spreadArgs(origResume, arguments, this); | ||
this.paused = false; | ||
if (this.__pausedDone) { | ||
this.__pausedDone(); | ||
} | ||
this.resume = resume; | ||
} | ||
extended(ParserStream).extend({ | ||
@@ -108,3 +92,3 @@ | ||
if (dataRow) { | ||
if (!self.paused) { | ||
if (!self.isPaused()) { | ||
self.__emitRecord(dataRow, count); | ||
@@ -211,3 +195,3 @@ } else { | ||
self.lines = lineData; | ||
if (!self.paused) { | ||
if (!self.isPaused()) { | ||
done(); | ||
@@ -221,3 +205,3 @@ } else { | ||
this.lines = lineData; | ||
if (!this.paused) { | ||
if (!this.isPaused()) { | ||
done(); | ||
@@ -232,5 +216,9 @@ } else { | ||
__doFlush: function (callback) { | ||
//increment row count so we aren't 0 based | ||
this.emit("end"); | ||
callback(); | ||
try { | ||
//increment row count so we aren't 0 based | ||
this.emit("end"); | ||
callback(); | ||
} catch (e) { | ||
callback(e); | ||
} | ||
}, | ||
@@ -244,3 +232,3 @@ | ||
callback(err); | ||
} else if (!self.paused) { | ||
} else if (!self.isPaused()) { | ||
self.__doFlush(callback); | ||
@@ -254,3 +242,3 @@ } else { | ||
} else { | ||
if (!this.paused) { | ||
if (!this.isPaused()) { | ||
this.__doFlush(callback); | ||
@@ -273,9 +261,27 @@ } else { | ||
pause: function () { | ||
if (!this.paused) { | ||
this.paused = true; | ||
this.emit("pause"); | ||
__flushPausedBuffer: function () { | ||
var buffered = this.__buffered, l = buffered.length; | ||
if (l) { | ||
var entry; | ||
while (buffered.length) { | ||
entry = buffered.shift(); | ||
this.__emitRecord(entry[0], entry[1]); | ||
//handle case where paused is called while emitting data | ||
if (this.isPaused()) { | ||
return; | ||
} | ||
} | ||
buffered.length = 0; | ||
} | ||
if (this.__pausedDone) { | ||
var done = this.__pausedDone; | ||
this.__pausedDone = null; | ||
done(); | ||
} | ||
}, | ||
isPaused: function () { | ||
return !!this.__paused; | ||
}, | ||
emit: function (event) { | ||
@@ -288,2 +294,8 @@ if (event === "end") { | ||
} else { | ||
if (event === "pause") { | ||
this.__paused = true; | ||
} else if (event === "resume") { | ||
this.__paused = false; | ||
this.__flushPausedBuffer(); | ||
} | ||
spreadArgs(origEmit, arguments, this); | ||
@@ -293,27 +305,2 @@ } | ||
resume: function () { | ||
if (this.paused) { | ||
this.paused = false; | ||
var buffered = this.__buffered, l = buffered.length; | ||
if (l) { | ||
var entry; | ||
while (buffered.length) { | ||
entry = buffered.shift(); | ||
this.__emitRecord(entry[0], entry[1]); | ||
//handle case where paused is called while emitting data | ||
if (this.paused) { | ||
return; | ||
} | ||
} | ||
buffered.length = 0; | ||
} | ||
if (this.__pausedDone) { | ||
var done = this.__pausedDone; | ||
this.__pausedDone = null; | ||
done(); | ||
} | ||
this.emit("resume"); | ||
} | ||
}, | ||
on: function (evt) { | ||
@@ -320,0 +307,0 @@ if (evt === "data" || evt === "readable") { |
{ | ||
"name": "fast-csv", | ||
"version": "0.5.2", | ||
"version": "0.5.3", | ||
"description": "CSV parser and writer", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -156,3 +156,3 @@ [![build status](https://secure.travis-ci.org/C2FO/fast-csv.png)](http://travis-ci.org/C2FO/fast-csv) | ||
csv() | ||
csv | ||
.fromStream(stream) | ||
@@ -173,3 +173,3 @@ .on("data", function(data){ | ||
csv() | ||
csv | ||
.fromStream(stream, {headers : true}) | ||
@@ -176,0 +176,0 @@ .on("data", function(data){ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
132041
914