json-input-stream
transforms the incoming data into a JSON object.
I made this because I always use JSON objects as response from my API, and using fs.createReadStream
with a pipeline to the response would send the inside of the file, without the pretty looking JSON response. This way I still have the JSON responses, and don't run out of memory if using fs.readFileSync
on huge files and creating the JSON response with the returned data from fs.readFileSync
.
data
- The object you want the incoming data to be transformed into. This object must contain theJsonInputStream.OUTPUT_LOCATION
variable, this is where the input data is going to be located.
Example:
let JsonInputStream = require('json-input-stream');
let fs = require('fs');
fs.createReadStream('./content-file.txt', 'utf8')
.pipe(JsonInputStream({
success: true,
result: {
content: JsonInputStream.OUTPUT_LOCATION
}
}))
.pipe(fs.createWriteStream('./json-file.json'));