Skip to content
This repository was archived by the owner on Aug 5, 2022. It is now read-only.

Commit cdafdf2

Browse files
committed
duplexed streams
1 parent 00c59b4 commit cdafdf2

File tree

1 file changed

+17
-20
lines changed

1 file changed

+17
-20
lines changed

index.js

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,28 @@
11
const Excel = require('exceljs')
22
const through = require('through2')
33
const duplex = require('duplexify')
4-
const Stream = require('stream')
5-
const readable = new Stream.Readable()
64

75
module.exports = () => {
86
const input = through()
7+
const second = through()
98
const workbook = new Excel.Workbook()
10-
readable._read = () => {
11-
let headers = null
12-
const reader = workbook.xlsx.read(input)
13-
.then((worksheet) => {
14-
workbook.eachSheet((sheet, id) => {
15-
sheet.eachRow((row, id) => {
16-
if (id === 1) {
17-
headers = row.values
18-
return
19-
}
20-
let item = {}
21-
row.values.forEach((v, k) => {
22-
item[headers[k]] = v
23-
})
24-
readable.push(JSON.stringify(item))
9+
10+
let headers = null
11+
const reader = workbook.xlsx.read(input)
12+
.then((worksheet) => {
13+
workbook.eachSheet((sheet, id) => {
14+
sheet.eachRow((row, id) => {
15+
if (id === 1) {
16+
headers = row.values
17+
return
18+
}
19+
let item = {}
20+
row.values.forEach((v, k) => {
21+
item[headers[k]] = v
2522
})
23+
second.push(JSON.stringify(item))
2624
})
27-
readable.push(null)
2825
})
29-
}
30-
return duplex(input, readable)
26+
})
27+
return duplex.obj(input, second)
3128
}

0 commit comments

Comments
 (0)