JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 20622
  • Score
    100M100P100Q139373F

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

Package Exports

  • jdataview

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (jdataview) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Build Status 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

Demos

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

  • BMP viewer with ability to load files by URL or using File API, parsing them using library and rendering with Canvas (no <img /> elements at all).

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

Please tell us if you made something with jDataView :)

License

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