I have a new project where I need to parse binary files in Javascript, and it would be very convenient to have the Actionscript ByteArray class. I have ported a big portion of the read() functions from the ByteArray class to a new Javascript class. I did not port any of the write() functions since my current project does not need them, but if there is enough demand I would consider porting them too. The class was written with very high performance in mind. Here is a benchmark against one of the only other Javascript binary decoders I could find:
To use it, just instantiate an a3d.ByteArray() and be sure to supply the two parameters: a string representing the binary data, and an enumeration for endianness of either a3d.Endian.BIG or a3d.Endian.LITTLE. You can fetch a binary file by overriding the mimeType on the XmlHttpRequest as demonstrated in Ilmari Heikkinen's binary parser. Here's an example that assumes jQuery is available:
function log(text) {console.log(text);}
var files = [{filename: 'bigendian.blob', endian: a3d.Endian.BIG, name: 'Big Endian'},
{filename: 'littleendian.blob', endian: a3d.Endian.LITTLE, name: 'Little Endian'}];
for (var fileIndex in files) {
var file = files[fileIndex];
$.ajax({async: false, url: file['filename'], beforeSend: function(xhr) {
xhr.overrideMimeType('text/plain; charset=x-user-defined');
}, success: function(data){
log(file['name']);
var ba = new a3d.ByteArray(data, file['endian']);
log(ba.readBoolean());
log(ba.readBoolean());
log(ba.readByte());
log(ba.readShort());
log(ba.readShort());
log(ba.readUnsignedInt());
log(ba.readInt());
log(ba.readInt());
log(ba.readFloat());
log(ba.readFloat());
log(ba.readDouble());
log(ba.readDouble());
log(ba.readDouble());
log(ba.readDouble());
log(ba.readDouble());
log(ba.readDouble());
log('');
}});
}
Parts of the source were originally taken from Ilmari Heikkinen's binary parser.
Here are full source and minified versions:
Comments
agree
I'm understand :) Obat Peninggi Badan Anak
very interesting for once
very interesting for once kata kata bijak
http://100resepmasakan.com/ h
http://100resepmasakan.com/ http://100resepmasakan.com/category/resep-kue-kering-dan-basah/ http://100resepmasakan.com/category/resep-ayam-bakar-goreng-kecap-panggang-rica/ http://100resepmasakan.com/category/resep-cara-membuat-bolu-kukus/ http://100resepmasakan.com/category/resep-kue-ulang-tahun-cubit-donat-semprit-kacang-bawang/ http://100resepmasakan.com/category/resep-kue-lumpur-kering-coklat-roti-tradisional/ http://100resepmasakan.com/category/resep-masakan-serba-ayam/ http://100resepmasakan.com/category/resep-masakan-udang-ikan-gado-pastel-batagor/ http://100resepmasakan.com/category/resep-kue-nastar-tart-lapis-putri-salju-pukis/ http://100resepmasakan.com/category/resep-menu-masakan-jawa-padang-ikan-bakar-pepes-tahu/ http://100resepmasakan.com/category/resep-nasi-kuning-perkedel-kentang-semur-daging-tongseng/ http://100resepmasakan.com/category/resep-opor-ayam-martabak-sayur-asem-cake-risoles/ http://100resepmasakan.com/category/resep-pancake-donat-kentang-lasagna-brownies-kue-kukus/ http://100resepmasakan.com/category/resep-soto-betawi-sayur-lodeh-nasi-uduk-rawon/
Ucapan terimakasih
hola
l time:
There are currently 1 user and 0 guests online. There are currently 1 user and 0 guests online. katamutiarabijakcinta katamutiarabijakcinta katamutiarabijakcinta katamutiarabijakcinta katamutiarabijakcinta katamutiarabijakcinta katamutiarabijakcinta katamutiarabijakcinta katamutiarabijakcinta katamutiarabijakcinta katamutiarabijakcinta
Thanks
Very nice post. Thank you for sharing more
very useful this web for me
very useful this web for me kata kata mutiara, kata kata bijak , kata kata lucu , kata kata romantis , kata kata galau
منتديات العراق اغاني
منتديات العراق اغاني عراقية ابراج اليوم تعيينات
منتديات جرح السنين منتديات
منتديات جرح السنين منتديات العراق
cinta
very interesting article once made at read. .. trima kasih khasiat , kumpulan kata kata lucu kata kata bijak kehidupan , kata kata cinta mario teguh , kata mutiara motivasi , kata bijak romantis , cahaya , kata cinta
Post new comment