Skip to content

Latest commit

 

History

History
28 lines (22 loc) · 1.5 KB

README.md

File metadata and controls

28 lines (22 loc) · 1.5 KB

npm version npm downloads dependencies Status license:mit

json-input-stream

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.

Documentation

Transform(data)

  • data - The object you want the incoming data to be transformed into. This object must contain the JsonInputStream.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'));