jbinary

High-level I/O for binary data.

npm install jbinary
6 downloads in the last day
7 downloads in the last week
71 downloads in the last month

Build Status NPM version

jBinary - High-level I/O for binary data.

jBinary makes it easy to work with binary files in JavaScript.

It works on top of jDataView (extended DataView polyfill).

Was inspired by jParser and derived as new library with full set of I/O operations for manipulations on binary data in JavaScript.

How can I use it?

Typical scenario:

  • Describe typeset with JavaScript-compatible declarative syntax (jBinary will do type caching for you).
  • Create jBinary instance from memory or from data source and your typeset.
  • Read/write data just as native JavaScript objects!

Check out wiki for detailed API documentation.

Is there any example code?

Sure, how about TAR archive modification:

// configuring paths for Require.js
// (you can use CommonJS (Component, Node.js) or simple script tags as well)
require.config({
  paths: {
    jdataview: '//jdataview.github.io/dist/jdataview',
    jbinary: '//jdataview.github.io/dist/jbinary',
    TAR: '//jdataview.github.io/jBinary.Repo/typeSets/tar' // TAR archive typeset
  }
});

require(['jbinary', 'TAR'], function (jBinary, TAR) {
  // loading TAR archive with given typeset
  jBinary.load('http://corsproxy.com/jdataview.github.io/jBinary.Repo/demo/tar/sample.tar', TAR)
  .then(function (jb/* : jBinary */) {
    // read everything using type aliased in TAR['jBinary.all']
    var files = jb.readAll();

    // do something with files in TAR archive (like log info and rename them to upper case)
    files.forEach(function (file) {
      console.log(file.name + ' (' + Math.round(file.size / 1024) + ' KB)');
      file.name = file.name.toUpperCase();
    });

    jb.seek(0); // reusing same instance (and memory buffer) by resetting pointer
    jb.writeAll(files); // writing entire content from files array
    jb.saveAs('sample.new.tar'); // saving file under given name
  });
});

Run or edit it on JSBin.

What is already created?

Screenshot Advanced demo that shows abilities and performance of jBinary - Apple HTTP Live Streaming player which converts MPEG-TS video chunks from realtime stream to MP4 and plays them immediately one by one while converting few more chunks in background.

Also check out jBinary.Repo for advanced usage and demos of some popular file formats (and feel free to submit more!).

What license is it issued under?

This library is provided under MIT license.

npm loves you