Last active
March 23, 2017 14:37
-
-
Save vicatcu/d4ed539f223f7f250da570b502db215c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let fs = require('fs'); | |
let CombinedStream = require('combined-stream2'); | |
let path = require('path'); | |
let parseStream = require('json-parse-stream'); | |
let getStreamedDir = (file) => { | |
let combinedStream = CombinedStream.create(); | |
let extensions = ['.json']; | |
if (fs.lstatSync(file).isDirectory()) { | |
fs.readdirSync(file) | |
.filter(f => (extensions.indexOf(path.extname(f)) >= 0)) | |
.forEach(f => { | |
let fpath = path.join(file, f); | |
combinedStream.append(fs.createReadStream(fpath).pipe(parseStream())); | |
}); | |
} | |
return combinedStream; | |
} | |
} | |
let s = getStreamedDir('my_folder'); | |
// does s emit 'data' events? | |
s.on('data', (data) => { | |
console.log('data: ', data); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let fs = require('fs'); | |
let CombinedStream = require('combined-stream2'); | |
let path = require('path'); | |
let parseStream = require('json-parse-stream'); | |
let getStreamedDir = (file, extensions) => { | |
let combinedStream = CombinedStream.create(); | |
if (fs.lstatSync(file).isDirectory()) { | |
fs.readdirSync(file) | |
.filter(f => (extensions.length == 0) || (extensions.indexOf(path.extname(f)) >= 0)) | |
.forEach(f => { | |
let fpath = path.join(file, f); | |
combinedStream.append(fs.createReadStream(fpath)); | |
}); | |
} | |
return combinedStream; | |
} | |
} | |
let = getStreamedDir('my_folder', ['.json']).pipe(parseStream()); | |
/* | |
... the following error happens only when I do .pipe(parseStream()); | |
Unhandled rejection TypeError: Cannot read property 'mode' of undefined | |
at Stream.write (file:///home/vic/project.js:125137:33) | |
at Stream.stream.write (file:///home/vic/project.js:125535:11) | |
at Stream.ondata (stream.js:31:26) | |
at emitOne (events.js:96:13) | |
at Stream.emit (events.js:188:7) | |
at drain (file:///home/vic/project.js:125545:16) | |
at Stream.stream.queue.stream.push (file:///home/vic/project.js:125551:5) | |
at emit (file:///home/vic/project.js:125486:12) | |
at Array.t_base (file:///home/vic/project.js:125303:24) | |
at Stream.write (file:///home/vic/project.js:125286:18) | |
at Stream.stream.write (file:///home/vic/project.js:125535:11) | |
at emitOne (events.js:96:13) | |
at Stream.emit (events.js:188:7) | |
at Stream.stream.write (file:///home/vic/project.js:124694:12) | |
at CombinedStream.ondata (_stream_readable.js:555:20) | |
at emitOne (events.js:96:13) | |
at CombinedStream.emit (events.js:188:7) | |
at readableAddChunk (_stream_readable.js:176:18) | |
at CombinedStream.Readable.push (_stream_readable.js:134:10) | |
at file:///home/vic/project.js:110764:17 | |
at tryCatcher (file:///home/vic/project.js:4053:23) | |
Unhandled rejection TypeError: Cannot read property 'mode' of undefined | |
at Stream.write (file:///home/vic/project.js:125137:33) | |
at Stream.stream.write (file:///home/vic/project.js:125535:11) | |
at Stream.ondata (stream.js:31:26) | |
at emitOne (events.js:96:13) | |
at Stream.emit (events.js:188:7) | |
at drain (file:///home/vic/project.js:125545:16) | |
at Stream.stream.queue.stream.push (file:///home/vic/project.js:125551:5) | |
at emit (file:///home/vic/project.js:125486:12) | |
at Array.t_base (file:///home/vic/project.js:125303:24) | |
at Stream.write (file:///home/vic/project.js:125286:18) | |
at Stream.stream.write (file:///home/vic/project.js:125535:11) | |
at emitOne (events.js:96:13) | |
at Stream.emit (events.js:188:7) | |
at Stream.stream.write (file:///home/vic/project.js:124694:12) | |
at CombinedStream.ondata (_stream_readable.js:555:20) | |
at emitOne (events.js:96:13) | |
at CombinedStream.emit (events.js:188:7) | |
at readableAddChunk (_stream_readable.js:176:18) | |
at CombinedStream.Readable.push (_stream_readable.js:134:10) | |
at file:///home/vic/project.js:110764:17 | |
at tryCatcher (file:///home/vic/project.js:4053:23) | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment