Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

jdataview

jDataView65.3k2.5.0TypeScript support: definitely-typed

A unique way to work with a binary file in the browser and the server.

buffer, binary, data, file, dataview, read, write, manipulation

readme

![Gitter](https://badges.gitter.im/Join Chat.svg) Build Status NPM version

jDataView - A unique way to work with a binary file in JavaScript.

jDataView provides convenient way to read and/or modify binary data in all the browsers. It follows the DataView Specification and even extends it for a more practical use.

Explanation

There are three ways to read a binary file from the browser.

  • The first one is to download the file through XHR with charset=x-user-defined. You get the file as a String, convert it to byte Array and you have to rewrite all the decoding and encoding functions (getUint16, getFloat32, ...). All the browsers support this.

  • Then browsers that implemented Canvas also added CanvasPixelArray as part of ImageData. It is fast byte array that is created and used internally by <canvas /> element for manipulating low-level image data. We can create such host element and use it as factory for our own instances of this array.

  • Then browsers that implemented WebGL added ArrayBuffer. It is a plain buffer that can be read with views called TypedArrays (Int32Array, Float64Array, ...). You can use them to decode the file but this is not very handy. It has big drawback, it can't read non-aligned data (but we can actually hack that). So they replaced CanvasPixelArray with Uint8ClampedArray (same as Uint8Array, but cuts off numbers outside 0..255 range).

  • A new revision of the specification added DataViews. It is a view around your buffer that can read/write arbitrary data types directly through functions: getUint32, getFloat64 ...

And one way to read a binary file from the server.

jDataView provides the DataView API with own convenient extensions using the best available option between Arrays, TypedArrays, NodeJS Buffers and DataViews.

Documentation

Advanced usage (jBinary)

For complicated binary structures, it may be hard enough to use only low-level get/set operations for parsing, processing and writing data.

In addition, most likely you might need convenient I/O methods for retrieving data from external sources such like local files (using File API or from Node.js), remote files (via HTTP(S)), data-URIs, Node.js streams etc. as well as for displaying generated content to user on webpage in image/video/audio/... containers or even as simple download link.

If you faced any of these problems, you might want to check out new jBinary library that works on top of jDataView and allows to operate with binary data in structured and convenient way.

Demos

HTTP Live Streaming realtime converter and player demo implemented using jBinary data structures. Screenshot


A World of Warcraft Model Viewer. It uses jDataView+jBinary to read the binary file and then WebGL to display it. Screenshot


A PhotoSynth WebGL Viewer by Visual Experiments. It uses jDataView to read the binary file and then WebGL to display it. Screenshot


A simple tar viewer. It is a "Hello World" demo of how easy it is to use the library.


JavaScript TrueTypeFont library demo which uses jDataView to read and display glyphs from TrueType file.

--

jBinary.Repo ready-to-use typesets and corresponding demos of using jDataView+jBinary for reading popular file formats like GZIP archives, TAR archives, ICO images, BMP images, MP3 tags etc.


Talking image - animation and audio in one package powered by HTML5 Audio, jDataView and jBinary.


Please tell us if you made something with jDataView :)

License

jDataView is issued under Do What The Fuck You Want To Public License :)

changelog

  • April 14 2014
    • Build process completely reworked and automated via Grunt + Travis CI.
  • August 23 2013
    • Added bitfield support (was considered to be borrowed from jBinary, but implemented faster and simpler version).
    • Completely dynamic one-time write* definition for all the set* methods.
    • Restructured tests using Mocha's BDD style, so now possible to test separate features and/or engines.
  • May 15 2013
    • jDataView got own account! More projects and demos coming soon.
  • May 30 2013:
    • RReverser added support for UTF-8 strings
    • Added support for 64-bit signed and unsigned integers (with precision loss outside the ±2^53 range when using primitive JS numbers due to IEEE.754 restrictions)
    • Added support for CanvasPixelArray as fast byte array for browsers that don't support Typed Arrays yet (like IE9)
    • Refactored code.
    • Added ability to test library on all the engines that are supported on current platform at once.
    • Added JSHint configuration according to project code guidelines and implemented corresponding QUnit test.
  • April 8 2013:
    • mmthomas implemented support for denormalized float values in setters
  • March 16 2013:
    • RReverser added support for setters in all supported implementations!
    • Performance improvements changing lower level constructs and type of inner buffers
    • Addition of [gs]etBytes, write*, wrapBuffer and slice helpers
    • Added support for any Array-like byte storage as input (Array, Uint8Array, Arguments, jQuery(Array), ...)
    • Added ability to create empty buffer (and operate on it) by passing count of bytes to wrapBuffer.
  • June 30 2012: Thanks to Mithgol for the changes!
    • Changed default to big endian from little endian to be compatible with DataView specification
    • Dropped support for NodeJS < 0.5.5, it was buggy anyway
    • Fixed an issue where ArrayBuffer would not work on NodeJS
    • Moved the compatibility checks outside of the read functions for hopefully better performance
  • December 22 2011: Added IE6-9 support by scintill
  • November 30 2011:
    • Added NodeJS Buffer support + NPM Package.
    • Added support for NaN and Infinity in the float shim.
    • Added buffer, byteLength and byteOffset attributes.
    • Fixed bugs using non zero byteOffset and added more bound checks.
  • September 21 2011: Added a missing littleEndian argument on getInt16.
  • April 28 2011: Seeking to the end of file no longer throws an error.
  • April 26 2011: Fixed a bug with extremely large unsigned 32bit being considered as signed. (Solution).
  • April 8 2011: Added littleEndian argument on the constructor. Opera 11.50 does not fully implement DataView, improved check.