This repository was archived by the owner on Aug 5, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +40
-4
lines changed
Expand file tree Collapse file tree 3 files changed +40
-4
lines changed Original file line number Diff line number Diff line change 4141```
4242
4343
44+ ### Options
45+
46+ ##### objectMode
47+
48+ > Enable [ objectMode] ( https://nodejs.org/api/stream.html#stream_object_mode )
49+
50+ default: true
51+
4452## [ License] ( LICENSE ) (MIT)
Original file line number Diff line number Diff line change @@ -2,9 +2,14 @@ var Excel = require('exceljs')
22var through = require ( 'through2' )
33var duplex = require ( 'duplexify' )
44
5- module . exports = function exceljsStream ( ) {
5+ var defaultOpts = {
6+ objectMode : true
7+ }
8+
9+ module . exports = function exceljsStream ( opts ) {
10+ opts = opts || defaultOpts
611 var input = through ( )
7- var second = through ( )
12+ var second = through ( { objectMode : opts . objectMode } )
813 var workbook = new Excel . Workbook ( )
914
1015 var headers = null
@@ -21,7 +26,11 @@ module.exports = function exceljsStream() {
2126 if ( ! headers ) return
2227 item [ headers [ k ] ] = v
2328 } )
24- second . push ( JSON . stringify ( item ) )
29+ if ( ! opts . objectMode ) {
30+ second . push ( JSON . stringify ( item ) )
31+ return
32+ }
33+ second . push ( item )
2534 } )
2635 } )
2736 second . emit ( 'end' )
Original file line number Diff line number Diff line change @@ -17,7 +17,26 @@ describe('exceljs-through-stream', function () {
1717 var res = [ ]
1818 file . pipe ( exs ( ) )
1919 . on ( 'data' , function ( d ) {
20- res . push ( JSON . parse ( String ( d ) ) )
20+ res . push ( d )
21+ } )
22+ . on ( 'end' , function ( ) {
23+ should ( res . length ) . equal ( 4 )
24+ should ( JSON . stringify ( res [ 0 ] ) ) . equal (
25+ JSON . stringify ( {
26+ row : 'row1' ,
27+ date : '2017-02-08T00:00:00.000Z' ,
28+ cost : 100 ,
29+ notes : 111
30+ } ) )
31+ done ( )
32+ } )
33+ } )
34+ it ( 'parse xlsx files with string mode' , function ( done ) {
35+ var file = fs . createReadStream ( __dirname + '/file.xlsx' )
36+ var res = [ ]
37+ file . pipe ( exs ( { objectMode : false } ) )
38+ . on ( 'data' , function ( d ) {
39+ res . push ( JSON . parse ( d ) )
2140 } )
2241 . on ( 'end' , function ( ) {
2342 should ( res . length ) . equal ( 4 )
You can’t perform that action at this time.
0 commit comments