Closed JasinYip closed 4 years ago
Could we offer an API which could let the users could parse a file without doing the stream jobs.
For example, users could use the API like this:
const json = require('big-json') const object = await json.parse('/path/to/file.json');
To implement this, we could wrap fs.createReadStream and json.createParseStream() like this:
fs.createReadStream
json.createParseStream()
module.exports.parse = function parse (filePath) { return new Promise((resolve, reject) => { const parseStream = json.createParseStream() parseStream.on('data', resolve) parseStream.on('error', reject) fs.createReadStream(filePath).pipe(parseStream) }) }
You might notice that I thought we could reuse the existed API parse for this new feature.
parse
Could I send a pull request for this?
Are you basically looking for a promise based interface for the parse and stringify methods?
stringify
You are right, maybe I should use the callback interface with utils.promisify👍
Could we offer an API which could let the users could parse a file without doing the stream jobs.
For example, users could use the API like this:
To implement this, we could wrap
fs.createReadStream
andjson.createParseStream()
like this:You might notice that I thought we could reuse the existed API
parse
for this new feature.Could I send a pull request for this?