Edit: HEY, I’m dumb. Make sure you call bytes.compress() if you want compression. Lolz.
I’m testing out AMF to see if I can save some file size, so I wrote a quick AIR2 test to see what the size difference is like before I muck about with RubyAMF. This is the test – you can copy + paste it right into CS5:
import flash.net.URLLoader;
import flash.events.Event;
import flash.net.URLRequest;
import flash.utils.ByteArray;
import flash.filesystem.File;
import flash.filesystem.FileStream;
import flash.filesystem.FileMode;
var path:String = "http://feeds.nytimes.com/nyt/rss/US";
var loader:URLLoader = new URLLoader();
var bytes:ByteArray = new ByteArray();
var xml:XML;
loader.addEventListener(Event.COMPLETE, loaded);
loader.load(new URLRequest(path));
function loaded(event:Event):void
{
xml = XML(loader.data);
bytes.writeObject(new XML(loader.data));
bytes.compress();
saveFiles();
}
function saveFiles():void
{
var file1:File = File.desktopDirectory.resolvePath("xmlTest.xml");
var file2:File = File.desktopDirectory.resolvePath("xmlTest.amf");
var stream1:FileStream = new FileStream();
var stream2:FileStream = new FileStream();
stream1.open( file1, FileMode.WRITE );
stream2.open( file2, FileMode.WRITE );
stream1.writeUTFBytes(xml.toXMLString());
stream2.writeBytes(bytes);
stream1.close();
stream2.close();
}
The URL is an XML file around 80k. Both of my output files are the exact same size. (Obviously the text one should be the same, but shouldn’t the AMF one be compressed?) What about all of this zlib compression and such that I keep hearing about? Why isn’t the bytearray object smaller?
http://troyworks.com/blog/2007/11/30/why-amf-rocks-and-beats-xml/
http://ted.onflash.org/2007/11/abcs-of-amf.php
Everyone seems to suggest that this should be smaller, but it certainly isn’t. Thoughts?