Skip to content

json-input-stream transforms the incoming data inside a JSON object.

License

Notifications You must be signed in to change notification settings

heartz66/json-input-stream

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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'));

About

json-input-stream transforms the incoming data inside a JSON object.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published