Permalink
Browse files

Clarify options handling

  • Loading branch information...
1 parent b82fdc1 commit dcf34c4aeeeb5d2eb014fb5cc9d291a98697b038 @wdavidw committed Sep 25, 2010
Showing with 50 additions and 21 deletions.
  1. +16 −12 lib/csv.js
  2. +34 −9 readme.md
View
@@ -30,16 +30,21 @@ module.exports = function(){
var CSV = function(){
// Set options
this.readOptions = {
- flags: 'r',
- encoding: 'utf8',
- bufferSize: 8 * 1024 * 1024,
delimiter: ',',
quote: '"',
- escape: '"'
+ escape: '"',
+ flags: 'r',
+ encoding: 'utf8',
+ bufferSize: 8 * 1024 * 1024
};
this.writeOptions = {
- bufferSize: null,
- lineBreaks: null
+ delimiter: null,
+ quote: null,
+ escape: null,
+ lineBreaks: null,
+ flags: 'w',
+ encoding: 'utf8',
+ bufferSize: null
};
}
CSV.prototype.__proto__ = EventEmitter.prototype;
@@ -107,12 +112,9 @@ module.exports = function(){
return this;
}
CSV.prototype.toPath = function(path, options){
- merge(options, {
- flags: 'w',
- encoding: 'utf8'
- });
- var stream = fs.createWriteStream(path, options);
- return this.toStream(stream, options);
+ merge(this.writeOptions, options);
+ var stream = fs.createWriteStream(path, this.writeOptions);
+ return this.toStream(stream, null);
}
// Transform API
@@ -123,6 +125,8 @@ module.exports = function(){
}
var csv = new CSV();
+
+ // Private API
function parse(chars){
chars = ''+chars;
View
@@ -35,33 +35,58 @@ Creating a source
Options are:
+- *delimiter*
+ Set the field delimiter, one character only, default to comma.
+
+- *quote*
+ Set the field delimiter, one character only, default to double quotes.
+
+- *escape*
+ Set the field delimiter, one character only, default to double quotes.
+
The following method are available:
-- *fromPath*
+- *fromPath*
Take a file path as first argument and optionnaly on object of options as a second arguments.
-- *fromStream*
+- *fromStream*
Take a readable stream as first argument and optionnaly on object of options as a second arguments.
-- *fromData*
+- *from*
Take a string, a buffer, an array or an object as first argument and optionnaly some options as a second arguments.
Creating a destination
----------------------
Options are:
-- *encoding* Default to 'utf8'
-- *lineBreaks* Default to 'auto', special values are 'auto', 'unix', 'mac', 'windows', 'unicode'.
-- *flag* Default to 'w', 'w' to create or overwrite an file, 'a' to append to a file. Apply when using the `toPath` method.
-- *bufferSize* Internal buffer holding data before being flush into a stream. Apply when destination is a stream.
+- *delimiter*
+ Default to the delimiter read option
+
+- *quote*
+ Default to the quote read option
+
+- *escape*
+ Default to the escape read option
+
+- *encoding*
+ Default to 'utf8'
+
+- *lineBreaks*
+ String used to delimite record rows or a special value; special values are 'auto', 'unix', 'mac', 'windows', 'unicode'; default to 'auto' (discovered in source).
+
+- *flag*
+ Default to 'w', 'w' to create or overwrite an file, 'a' to append to a file. Apply when using the `toPath` method.
+
+- *bufferSize*
+ Internal buffer holding data before being flush into a stream. Apply when destination is a stream.
The following method are available:
-- *toPath*
+- *toPath*
Take a file path as first argument and optionnaly on object of options as a second arguments.
-- *toStream*
+- *toStream*
Take a readable stream as first argument and optionnaly on object of options as a second arguments.
Transforming data

0 comments on commit dcf34c4

Please sign in to comment.