@@ -2,20 +2,40 @@ var Writable = require("stream").Writable;
22var util = require ( "util" ) ;
33var eol = require ( "os" ) . EOL ;
44function Result ( csvParser ) {
5- Writable . call ( this ) ;
5+ Writable . call ( this , csvParser . _options ) ;
6+ this . _option = csvParser . _options || { } ;
67 this . parser = csvParser ;
78 this . param = csvParser . param ;
8- this . buffer = this . param . toArrayString ? "" :"[" + eol ;
9+ this . buffer = this . _option . objectMode ? [ ] :"[" + eol ;
910 this . started = false ;
1011 var self = this ;
1112 this . parser . on ( "end" , function ( ) {
12- if ( ! self . param . toArrayString ) {
13+ if ( typeof self . buffer === "string" ) {
1314 self . buffer += eol + "]" ;
1415 }
1516 } ) ;
17+ this . _write = this . _option . objectMode ?_writeObject :_writeBuffer ;
1618}
1719util . inherits ( Result , Writable ) ;
18- Result . prototype . _write = function ( data , encoding , cb ) {
20+
21+ Result . prototype . getBuffer = function ( ) {
22+ return typeof this . buffer === "string" ?JSON . parse ( this . buffer ) :this . buffer ;
23+ } ;
24+
25+ Result . prototype . disableConstruct = function ( ) {
26+ this . _write = function ( d , e , cb ) {
27+ // console.log(typeof d,d);
28+ cb ( ) ; //do nothing just dropit
29+ } ;
30+ } ;
31+
32+
33+ function _writeObject ( data , encoding , cb ) {
34+ this . buffer . push ( data ) ;
35+ cb ( ) ;
36+ } ;
37+
38+ function _writeBuffer ( data , encoding , cb ) {
1939 if ( encoding === "buffer" ) {
2040 encoding = "utf8" ;
2141 }
@@ -32,15 +52,4 @@ Result.prototype._write = function(data, encoding, cb) {
3252 cb ( ) ;
3353} ;
3454
35- Result . prototype . getBuffer = function ( ) {
36- // console.log(this.buffer);
37- return JSON . parse ( this . buffer ) ;
38- } ;
39-
40- Result . prototype . disableConstruct = function ( ) {
41- this . _write = function ( d , e , cb ) {
42- cb ( ) ; //do nothing just dropit
43- } ;
44- } ;
45-
4655module . exports = Result ;
0 commit comments