Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge remote-tracking branch 'refs/remotes/eladb/sourceless-no-headers'

  • Loading branch information...
commit ee2d104bd4f719600f79363bc416d103eadf3449 2 parents d9c5ffa + e66ed66
@wdavidw authored
View
3  lib/csv.js
@@ -134,6 +134,9 @@ module.exports = function(){
state.line = data;
return flush();
}
+ if(state.count === 0 && csv.writeOptions.header === true){
+ write(csv.writeOptions.columns || csv.readOptions.columns);
+ }
write(data, preserve);
if(!transforming && !preserve){
state.count++;
View
16 test/write.coffee
@@ -106,6 +106,18 @@ describe 'write', ->
for i in [0...1000]
test.write ['Test '+i, i, '"']
test.end()
+ it 'should emit header even without a source', (next) ->
+ test = csv()
+ .toPath( "#{__dirname}/write/write_sourceless.tmp",
+ columns: [ 'col1', 'col2' ],
+ header: true,
+ lineBreaks: 'unix' )
+ .on 'end', ->
+ expect = fs.readFileSync("#{__dirname}/write/write_sourceless.out").toString()
+ result = fs.readFileSync("#{__dirname}/write/write_sourceless.tmp").toString()
+ result.should.eql expect
+ fs.unlink "#{__dirname}/write/write_sourceless.tmp", next
-
-
+ test.write col1: 'foo1', col2: 'goo1'
+ test.write col1: 'foo2', col2: 'goo2'
+ test.end()
View
3  test/write/write_sourceless.out
@@ -0,0 +1,3 @@
+col1,col2
+foo1,goo1
+foo2,goo2
Please sign in to comment.
Something went wrong with that request. Please try again.