Permalink
Browse files

Externalize stringier code; Remove all buffer related code

  • Loading branch information...
1 parent 639573d commit a2b8f8f7ed09ddf8be23e55ca3c1bf4f947c58a3 @wdavidw wdavidw committed Sep 3, 2012
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -104,17 +104,17 @@ Events
By extending the Node `EventEmitter` class, the library provides a few useful events:
-- *data* (function(data, index){})
+* *data* (function(data, index){})
Thrown when a new row is parsed after the `transform` callback and with the data being the value returned by `transform`. Note however that the event won't be called if transform return `null` since the record is skipped.
- The callback provide two arguments:
- `data` is the CSV line being processed (by default as an array)
- `index` is the index number of the line starting at zero
-
-- *end*
- In case your redirecting the output to a file using the `toPath` method, the event will be called once the writing process is complete and the file closed.
-
-- *error*
- Thrown whenever an error is captured.
+ The callback provide two arguments:
+ `data` is the CSV line being processed (by default as an array)
+ `index` is the index number of the line starting at zero
+* *end*
+ Emitted when the CSV content has been parsed.
+* *close*
+ Emitted when the underlying resource has been closed. For example, when writting to a file with `csv().to.path()`, the event will be called once the writing process is complete and the file closed.
+* *error*
+ Thrown whenever an error occured.
Columns
-------
View
@@ -6,14 +6,14 @@ var csv = require('..');
process.stdin.resume();
csv()
-.fromStream(process.stdin)
-.toPath(__dirname+'/sample.out')
+.from.stream(process.stdin)
+.to.path(__dirname+'/sample.out')
.transform(function(data){
data.unshift(data.pop());
return data;
})
-.on('data',function(data,index){
- console.log('#'+index+' '+JSON.stringify(data));
+.on('record',function(record, index){
+ console.log('#'+index+' '+JSON.stringify(record));
})
.on('end',function(count){
console.log('Number of lines: '+count);
View
@@ -1,13 +1,13 @@
var csv = require('..');
-var arr = [
+var data = [
[1,2,3,4,5],
[2,4,6,8,10]
];
csv()
-.from(arr)
-.toStream(process.stdout, {end: false}); //thows on csv.js line 150
+.from.array(data)
+.to.stream(process.stdout, {end: false}); //thows on csv.js line 150
/*
View
@@ -11,6 +11,13 @@ Parse a string which may hold multiple lines.
Private state object is enriched on each character until
transform is called on a new line.
+Internally, the code doesn't need to be async
+
+Events
+* row
+* end
+* error
+
###
Parser = (csv) ->
@writable = true
Oops, something went wrong.

0 comments on commit a2b8f8f

Please sign in to comment.