Tutorial by Examples

JavaScript has two primary ways to represent binary data in the browser. ArrayBuffers/TypedArrays contain mutable (though still fixed-length) binary data which you can directly manipulate. Blobs contain immutable binary data which can only be accessed through the asynchronous File interface. Conver...
DataViews provide methods to read and write individual values from an ArrayBuffer, instead of viewing the entire thing as an array of a single type. Here we set two bytes individually then interpret them together as a 16-bit unsigned integer, first big-endian then little-endian. var buffer = new Ar...
var data = 'iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACN' + 'byblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHx' + 'gljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=='; var characters = atob(data); var array = new Uint8Array(characters.length); for (var i = 0; i < characters.length; i++) { array[i] ...
TypedArrays are a set of types providing different views into fixed-length mutable binary ArrayBuffers. For the most part, they act like Arrays that coerce all assigned values to a given numeric type. You can pass an ArrayBuffer instance to a TypedArray constructor to create a new view of its data. ...
This example is inspired by this question. We'll assume you know how to load a file using the File API. // preliminary code to handle getting local file and finally printing to console // the results of our function ArrayBufferToBinary(). var file = // get handle to local file. var reader = new...
For a convenient way to iterate through an arrayBuffer, you can create a simple iterator that implements the DataView methods under the hood: var ArrayBufferCursor = function() { var ArrayBufferCursor = function(arrayBuffer) { this.dataview = new DataView(arrayBuffer, 0); this.size = a...

Page 1 of 1