W3C home > Mailing lists > Public > whatwg@whatwg.org > February 2010

[whatwg] canvas, img, file api and blobs

From: Lino Mastrodomenico <l.mastrodomenico@gmail.com>
Date: Wed, 17 Feb 2010 02:23:17 +0100
Message-ID: <cc93256f1002161723g1ba633fbuc1364cf6a5f88e8@mail.gmail.com>
2010/2/16 Joel Webber <jgw at google.com>:
> On Tue, Feb 16, 2010 at 2:25 PM, Stefan Haustein <haustein at google.com>
> wrote:
>>
>> Constructing ints / longs from bytes in Javascript will probably be slow,
>> so in addition to the typed arrays, we'd love to have some kind of access
>> that would be similar to Java's DataInput (+DataOutput, see
>> http://java.sun.com/j2se/1.4.2/docs/api/java/io/DataInput.html ), but with
>> endianess support....
>
> Agreed with Stefan's point, although technically you could implement
> getByte(), getShort(), et al with a bunch of TypedArray views onto a single
> ArrayBuffer. But this is really, really ugly, because in the general case
> you'd need 4 ByteArrays, 2 ShortArrays, etc. to deal with arbitrary offsets.

A mini language that describes arbitrary sequences of data types in
binary data is the one used by the Python module "struct"
(<http://docs.python.org/3.1/library/struct.html>).

E.g. "< 3b x 2i" represents 3 signed chars, one byte of padding and 2
signed 32-bit ints, little-endian.

It can be an inspiration for functions or methods that extract data
out of byte arrays and convert JS variables back to binary.

Another thing that people will probably ask is the possibility of
converting binary data to and from strings. Obviously for both
directions the user has to provide an encoding (e.g. UTF-8).

-- 
Lino Mastrodomenico
Received on Tuesday, 16 February 2010 17:23:17 UTC

This archive was generated by hypermail 2.3.1 : Monday, 13 April 2015 23:08:55 UTC