You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP
Socket
Sign inDemoInstall
Socket

json-stream-wrapper

Package Overview
Dependencies
Maintainers
3
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-stream-wrapper

A stream wrapper which wraps a stream into a JSON object

0.0.9
Source
npm
Version published
Weekly downloads
47
-54.37%
Maintainers
3
Weekly downloads
 
Created
Source

node-json-stream-wrapper

A stream wrapper which wraps a stream into a JSON object

Build Status

Example Usage

import jsonStreamWrapper, {Base64Stream} from 'json-stream-wrapper';

import {createReadStream} from 'fs';
import {post} from 'request';

createReadStream('<example-file>')
  .pipe(new Base64Stream())
  .pipe(jsonStreamWrapper({example: 1}, 'file'))
  .pipe(post({
      url: 'http://target',
      json: true
    }));
    
// body of the http-request of the target-server:
// {
//    "example" : 1,
//    "file" : "<FILE_CONTENT_IN_BASE64>"
// }

or:

import jsonStreamWrapper, {Base64Stream} from 'json-stream-wrapper';

import {createReadStream} from 'fs';

let fstream = createReadStream('<example-file>');

const foo = fstream
  .pipe(new Base64Stream())
  .pipe(jsonStreamWrapper({example: 1}, 'file'));

streamToObject(foo, (obj) => {
  console.log(obj);
  // output:
  // {
  //    "example" : 1,
  //    "file" : "<FILE_CONTENT_IN_BASE64>"
  // }

});



function streamToObject(stream, cb) {
  const chunks = [];
  stream.on('data', (chunk) => {
    chunks.push(chunk);
  });
  stream.on('end', () => {
    cb(JSON.parse(chunks.join('')));
  });
}

FAQs

Package last updated on 08 Feb 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts