csv-string
Advanced tools
Comparing version 3.0.3 to 3.1.0
'use strict'; | ||
var Writable = require('stream').Writable; | ||
var Transform = require('stream').Transform; | ||
var Parser = require('./parser.js'); | ||
function Streamer(options) { | ||
Writable.call(this, options); | ||
Transform.call(this, { | ||
readableObjectMode: true, | ||
writableObjectMode: false, | ||
}); | ||
this.buffer = ''; | ||
@@ -14,9 +17,8 @@ this.sep = (options && options.separator) ? options.separator : undefined; | ||
Streamer.prototype = Object.create( | ||
Writable.prototype, { constructor: { value: Streamer }}); | ||
Transform.prototype, { constructor: { value: Streamer }}); | ||
Streamer.prototype._write = function (chunk, encoding, done) { | ||
Streamer.prototype._transform = function(chunk, encoding, done) { | ||
this.buffer = this.buffer.concat(chunk.toString()); | ||
if (this.sep === undefined) { | ||
@@ -42,3 +44,3 @@ // try to detect the separator if not provided | ||
rows.forEach(function (row) { | ||
self.emit('data', row); | ||
self.push(row); | ||
} | ||
@@ -50,3 +52,3 @@ ) | ||
Streamer.prototype.end = function () { | ||
Streamer.prototype._flush = function (done) { | ||
var csv = new Parser(this.buffer, this.sep, this.quo); | ||
@@ -57,9 +59,9 @@ var rows = csv.File(); | ||
rows.forEach(function (row) { | ||
self.emit('data', row); | ||
self.push(row); | ||
} | ||
) | ||
} | ||
this.emit('end'); | ||
done(); | ||
}; | ||
module.exports = Streamer; |
{ | ||
"name": "csv-string", | ||
"version": "3.0.3", | ||
"version": "3.1.0", | ||
"author": "Nicolas Thouvenin <nthouvenin@gmail.com>", | ||
@@ -5,0 +5,0 @@ "contributors": [ |
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
28431
719