Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

binary-extract

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

binary-extract

Extract values from a binary json blob

  • 0.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

binary-extract

Extract one or more values from a buffer of json without parsing the whole thing.

build status

Example

var extract = require('binary-extract');

var buf = new Buffer(JSON.stringify({
  foo: 'bar',
  bar: 'baz',
  nested: {
    bar: 'nope'  
  } 
}));

var value = extract(buf, 'bar');
// => 'baz'

var values = extract(buf, ['foo', 'nested'])
// => ["bar", {"bar":"nope"}]

Perf

With the object from bench.js, extract() is ~2-4x faster than JSON.parse(buf.toString()). It is also way more memory efficient as the blob stays out of the V8 heap.

The big perf gain comes mainly from not parsing everything and not converting the buffer to a string.

Installation

$ npm install binary-extract

API

extract(buf, keys)

Extract the value of keys in the json buf.

The value can be any valid JSON structure.

If keys is a String, returns a value. If keys is an Array of keys, returns an array of values.

License

MIT

FAQs

Package last updated on 28 May 2014

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc