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
cheap links of london sites
The easiness of gold necklaces and authentic life people links of London to complete the quest for really enjoy, In 2010, sweetie bracelets unveiled boutique bracelet, in contrast to the clumsy thick bracelet, the revolutionary bracelet build a elegant and wonderful sensitive elegance
Performance Javascript
This question is related to another question of mine about data compression. Here is my idea: there are lot of Web2.0 apps out there that constantly sending out JSON text requests. Affiliate Programs
High Performance Javascript
The difference would depend on how restrictive the stock air filter is compared to the HP one, or what temperature air the engine is getting now versus what it would get with CAI. Whole Life Insurance
ByteArray
Your counter counts the number of lines, not the number of character, and then you write the number of lines out, incrementing it, as you do something that escapes me. Pandora Beads
モバゲーPC版 モバゲーPC版 モバゲーPC版 モバゲーP
モバゲーPC版 モバゲーPC版 モバゲーPC版 モバゲーPC版
Canada roses
Canada roses Hey great stuff, thank you for sharing this useful information and i will let know my friends as well.
I expected to see low frame
I expected to see low frame rates, solely because of the straightforward marshaling technique I was using for the positions and color values. Both arrays are set through bytearrays marshaled through an emit method in C++.. speel-keno.nl
ByteArray write
Are you going to work on the write part as well anytime soon?
above ground swimming pools
Building a solid community like this will help us see wider through the horizon.And you know life is enriched even more.
louis vuittion
I didn't want to stop there.642-515 I wanted to optimize things as much as I could to make the encoder fast. This took me several days. I found optimized encoder versions for flash and haxe floating around the net (Faster JPEG Encoding with Flash Player 10) and tried the optimizations used there in my javascript version. 642-524 As you can seen in the benchmarks below I was quite successful.chanel chanel handbags chanel bags louis vuitton
louis vuitton handbags louis vuitton bags
sanejenny
A nice pictures of celebration. All of the picture a designed very well. They look so contrast and like a real picture.
sanejenny
Building a solid community like this will help us see wider through the horizon. And you know life is enriched even more.
筆おろし
はじめまして~(人〃∇〃)
みんな良かったらいつでも絡んでね♪ 必ずカエラを探してね!! 一応プロフ載せておきます!! カエラ(22)埼玉出身 良く似てるって言われるのが黒木メイサちゃん☆ 男女関係なく誰とでも仲良くなりたいので みんなとお友達希望♪
お邪魔しました^^ ブログ更新頑張って下さいね☆彡 愛情持って育てたらブログも愛おしくなるよね♪
またよかったらカエラのお部屋にも遊びに来てね(*´∀`)ノ
Not quite working
Thank you for writing this class. It seems like what I need. However, I can't seem to get it working. I'm using a Flash camera program to output a Jpeg image as raw data. The error message I get is:
filename: bytearray.min.js lineNumber: 16 message: "this.data.charCodeAt is not a function" name: "TypeError" stack: "()@http://myserver/bytearray.min.js:16 ([object Object])@http://173.201.21.31/Mock_OSHA_Inspection_sync/camera.php:31 @http://myserver/camera.php:0 "
It would appear that it's receiving the object as [object Object] rather than a ByteArray. I'm not sure what to do about this. Here's my code:
receiveData = function (data) { try{ var ba = new a3d.ByteArray(data,a3d.Endian.BIG); console.log(ba.readByte()); }catch(err) {
console.log(err); }
This function gets called by the Flash program like this: ExternalInterface.call("receiveData", _imageData);
Any ideas as to what I might be doing wrong?
Coding looks fun, I am one of
Coding looks fun, I am one of those who always liked to code and I tried my hands at C++ but unfortunately couldn't keep my focus going but I am still very keen to learn some more if I find the correct e-book and time.
It just fascinates me about the power in the hand of a developer, they can code anything they want and can put all their creative ideas into it.
las vegas short sale agent
It can be pretty difficult to
It can be pretty difficult to wrap your head around the concept of matrix transformations. To debug matrix differences across web browsers, I made a nifty matrix sandbox page to play around with the numbers and see the effects in realtime. Just drag the sliders around and see what happens to the square in the middle. Promotional Items Promotional Gift Store Promotional Products
Java script is not easy to
Java script is not easy to learn. I think this is so good to use. I think you are so right about this issue. oklahoma city mesothelioma attorneys
Thanks for your sharing. I
Thanks for your sharing. I tyhink I will try to use your program. So, can you tell me how to use that more detail??
I think I don't like to read
I think I don't like to read programming language..That's make me confused and I don't know what the meaning. classified ads |job listings|adjustable beds
The information you offered
The information you offered is very useful. I have learned a lot. And it will help me in the future, thanks! free ads |part time jobs|faucets
aboutbuys
65W Asus M6VA Laptop AC Power Adapter 65W Asus M6V Laptop AC Power Adapter 65W Asus M6N Laptop AC Power Adapter 65W Asus M6B00N Laptop AC Power Adapter 65W Asus M6800N Laptop AC Power Adapter 65W Asus M6700N Laptop AC Power Adapter 65W Asus M6000N Laptop AC Power Adapter 65W Asus M2000N Laptop AC Power Adapter 65W Asus M2000 Laptop AC Power Adapter 65W Asus G2S Laptop AC Power Adapter 65W Asus G2 Laptop AC Power Adapter 65W Asus G1S Laptop AC Power Adapter 65W Asus G1 Laptop AC Power Adapter 65W Asus F9J Laptop AC Power Adapter 65W Asus F9F Laptop AC Power Adapter 65W Compaq Presario M2108 Laptop AC Adapter 18.5V 3.5A 65W Compaq Presario 2811 Laptop AC Adapter 18.5V 3.5A 65W Compaq Presario M2099 Laptop AC Adapter 18.5V 3.5A 65W Compaq Presario M2015 Laptop AC Adapter 18.5V 3.5A 65W Compaq Presario M2007 Laptop AC Adapter 18.5V 3.5A 65W Compaq Presario M2001 Laptop AC Adapter 18.5V 3.5A Original HP/Compaq Laptop/NoteBook Power AC Adapter Compaq 19V 6.3A AC Adapter 5.5X2.5mm 308745-001 Compaq Evo N110 AC Adapter 18.5V 3.8A power cord included Compaq Emachine 18.5V 4.9A AC Adapter 239428-001
aboutbuys
65W Asus A8Js Laptop AC Power Adapter 65W Asus A8M Laptop AC Power Adapter 65W Asus A8Sc Laptop AC Power Adapter 65W Asus F2J Laptop AC Power Adapter 65W Asus F2Je Laptop AC Power Adapter 65W Asus W2V Laptop AC Power Adapter
cheap hosting | windows vps
cheap hosting | windows vps | cheap vps | ucvhost
Tiffany & Co
In diesen Jahren wurden Tiffany and Co jacken von immer mehr Leute beliebt, wenn Sie auch eine moncler jake kaufen möchten, empfehlen wir die Website Tiffany and Co monclerdaunenjacke.com. Die Waren hier sind preiswert und von guter Qualität
Taşınabilir bilgisayar son
Taşınabilir bilgisayar son yıllarda ülkemizde kullanım oranı açısından yükselişte olan bir ürün grubudur.Dizüstü bilgisayarların en önemli artılarından biri taşınabilir olmasıdır.Bu ürün grubu içerisinde öne çıkan markalar dell notebook , asus notebook , hp notebook ,toshiba notebook olarak sıralanabilir.Sony vaio notebooklar da kasa kalitesi ve dayanıklılık ön plana çıkıyor. Sony vaio notebookların başka bir özelliği ise işlemci olarak çoğunlukla core 2 duo işlemciye sahip olmasıdır. Acer aspire ise fiyat performans oranı yüksek olan bir marka.Hp notebook compaq bilgisayar parçaları açısından kaliteli ve dayanıklı bir marka ve Türkiye piyasasına ilk giren notebook markalarından biri olduğu için kullanıcılarda güven duygusu uyandırıyor.Dizüstü bilgisayarların kullanım alanının genişletilmesi için giriş ve çıkış portları önemli bir özellik.Bir dizüstü bilgisayarda hdmi veya s-video girişinin bulunması laptopun lcd monitör veya Lcd Televizyon gibi görüntü aktarıcılara bağlanma imkanı sağlar.Dizüstü bilgisayarların birçok avantajının yanısıra bazı dezavantajlarıda vardır.Bu dezavantajların en başında ısınma sorunu bulunuyor.Bu sorunun giderilmesi için son yıllarda notebook soğutucu ve notebook standı ürünleri piyasaya giriş yaptılar. Ve alışveriş aracı oldu.
Buy cheap Links of London
Buy cheap Links of London jewellery at online jewellerybarnd UK store, including Links of London Necklaces, Links of London Charms, Links of London Earrings, links of london links london Hundreds of links of london jewellery in stock,Free Gift Wrapping, links of london Necklaces links of london Rings links of london Earrings Complete links of london jewellery collection,including necklaces,bracelets,earrings links of london Bracelets links of london Charms links london Sweetie Bracelets Best Discounted UK Tiffany Jewellery Sale Outlet provides designer Tiffany Ring, necklaces and other jewelry in wholesale price. UK Tiffany specializes in Tiffany jewellery Tiffany
I downloaded the sources for
I downloaded the sources for the AS3 jpeg encoder ( AS3 corelib) and analyzed the code. I'm not an expert in writing encoders, actually I think it would have taken me month to start from scratch. 642-359 The ActionScript code seemed tidy and my first step was to replace things not possible in javascript from the code. Then I wrote a little converter function to transform the 1-dimensional canvas image data array into a 2-dimensional array, 642-456 which the original encoder expects. To cut it short: In about 2 hours I had the first working version! It was surprising that it was that easy to get the first js-encoded jpeg displayed in the browser. Of course I didn't want to stop there.642-515 I wanted to optimize things as much as I could to make the encoder fast. This took me several days. I found optimized encoder versions for flash and haxe floating around the net (Faster JPEG Encoding with Flash Player 10) and tried the optimizations used there in my javascript version. 642-524 As you can seen in the benchmarks below I was quite successful.
write() implementation
Great work on this! I was looking for a JS port of the AS' ByteArray and voila! I didn't expect that someone has actually written one. :D
I was thinking about using binary data as a transport between a browser based app and the server, and I think I'll need both a reader/writer for that to work. Any chances of releasing the write() functions? Thanks!
very cool & good tip, thank
very cool & good tip, thank you very much for sharing.
Can I share this post on my JavaScript library?
Awaiting your response. Thank
I'm not sure what you're
I'm not sure what you're asking permission to do, but please feel free to link to this post from just about anywhere.
Post new comment