[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Public WebGL] DataView suggestions
- To: [email protected]
- Subject: [Public WebGL] DataView suggestions
- From: Christopher Chedeau - Vjeux <[email protected]>
- Date: Fri, 8 Apr 2011 12:52:35 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:date:message-id:subject:from:to :content-type; bh=/5+o/C+EteJAc3vRQtnWWgocVZOoSajRJ8zDBBlMfh0=; b=lQ7rDzsXiim5uYWN/6VQIQnt8uS7IbCp5+Odpo2Mth4SIO6/CkryaqJaG3iVlYtxgY 05xR35sUmuJ+2mfCBHjGNYLLVFB+q6ocG/5OEQoch+lDghGcwmMN8NBrw23iFwpPGWC2 ACYUwNRMQDFC9i2uhk5RKRyxbv9YKRs+zZioU=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=BxbXMcxOidZUhJLWTHejuFR1tF8ypOwKqLwhoMbCGT8WCsqhssoQAQ3zkKh0xDhZeS LXU3cq8FfHSZBtZEU6uw0ygjLY9RjtaFFZ1qi7djWObQ1+OqBO3Le/18CH1e+TBI9n1O Pl4Sm4nm0eP0E2Eec/733eCZaK8bDBGmLdC48=
- List-id: Public WebGL Mailing List <public_webgl.khronos.org>
- Sender: [email protected]
I have been working on a lib that provides DataView API for all the browsers (it uses the best feature available from String, Typed Array or DataView) called jDataView: https://github.com/vjeux/jsDataView/
While working on this library, I found that the current API was not really practical to use. Adding those few points would make the handling of binary data more enjoyable.
1) Addition of littleEndian to the constructor
A binary file is either in littleEndian or bigEndian form. It is therefore really annoying to have to define the endianness everytime you read a value. This is even more annoying since the default value is bigEndian whereas most files nowadays are in littleEndian.
To solve this, we can add a parameter littleEndian to the DataView constructor. When you read/write and the littleEndian value is undefined, this is the value from the constructor that is being used. I would also set bigEndian by default.
2) File cursor
Most of the time you read a file sequentially. With the current API, you have to keep a cursor of where you are at and this is extremely annoying.
You would like to write
var a = view.getInt8();
var b = view.getFloat32();
Instead you have to write
var cursor = 0;
var a = view.getInt8(cursor); cursor += 1;
var b = view.getFloat32(cursor); cursor += 4;
DataView could have an internal cursor initialized to 0 at creation. Every time you make a read/write, it would be set to the end of what has been read/written. byteOffset will be set to the cursor position. if undefined.
In order to manipulate the cursor, we would have two functions:
seek(byteOffset) and tell()
3) getChar and getString
Often, binary files also contain characters and strings. With the current API, this is extremely annoying to read those types of values.
I suggest to add 4 new functions:
setString(byteOffset, string, optional length)