ActionScript GZIP compression library

This is an ActionScript library for encoding (compressing and uncompressing) files using the GZIP compressed file format. The source code for the ActionScript GZIP encoding library is hosted on Google Code; the code is available under the MIT license.

Note: version .2 and previous were licensed under the Mozilla Public License, v. 1.1.

Where it’s been used:

You can leave a comment, or trackback from your own site.

24 Comments so far


  1. Danny Patterson is reported to have said:

    links from TechnoratiSince I actually needed to get at the raw binary gzip data returned by the server, I had to change my code to use the low-level URLLoader class that is built-in to Flash Player. To remove the GZIP header returned in the HTTP response data, I used anopen-source library


  2. Lynch Consulting Blog is reported to have said:

    links from Technoratimy best sherlock holmes head on I rapidly deduced that Charles as well as proxying the request was also decompressing it helpfully for me. Luckily I’d already come across the solution to the problem courtesy of Anirudh Sasikumar (GzipHTTPService) andPaul Robertson (Gzip Encoder). I made some minor modifications to Anirudh’s Gzip HTTP Service to do two things. Always send the header ‘Accept-Encoding’:’gzip’ if running a Desktop (Aka AIR) app. Handle the case where the Gzip response that comes back is not gzip compressed.


  3. Yahoo! Developer Network Blog is reported to have said:

    links from Technoratids largish amounts of data upstream (excluding images, which are already compressed), consider implementing client-side compression. It’s possible to get 1.5:1 compression with a simple LZW+Base64 function; if you’re willing to monkey with ActionScript you could probably doreal gzip compression. YSlow says you should flush() early and put Javascript at the bottom. The reasoning is sound: get the HTML portion out as quickly as possible so the browser can start downloading any referenced stylesheets and images. On the other hand, JS


  4. Adobe - Developer Center : Compressing files and data is reported to have said:

    Kramer auto Pingback[…] These files are from the open-source ActionScript GZIP compression library written by H. Paul […]


  5. Extending the Flex HTTP Service to Support Binary Data is reported to have said:

    Kramer auto Pingback[…] this particular case, we pass the binary data to Paul Robertson’s excellent GZIPEncoder3 and decode it to obtain the actual result and then pass it on to HTTPService’s processResult so […]


  6. Alex is reported to have said:

    Hi Paul,

    I was pretty excited to find your GZIP library and was going to use it in my project. But then I discovered that it doesn’t work with Flex. Flex’s implementation of ByteArray.compress() is different than AIR’s and supports only default zlib compression. Any idea why are they different? Will Flex ever support gzip?

    Thanks,
    Alex


  7. Paul is reported to have said:

    @Alex:

    Just to clarify, the library does work with Flex (I’ve only ever used it with Flex) as long as your Flex app runs in AIR. However, the library doesn’t work in Flash Player 9, so it doesn’t work in a Flex app that runs in the browser (or a non-Flex app that runs in the browser, for that matter).

    The additional functionality (compression using the Deflate algorithm rather than zlib) was added in AIR — as you’ve noted, Flash Player only supports zlib.

    The good news is that the functionality that was added in AIR has been rolled back into Flash Player for the next release (Flash Player “Astro”), which is currently available as a public beta. I haven’t updated the library to support that new functionality, obviously, but I plan to do so soon.


  8. はてなブックマーク - FZip - codeazur brasil lab is reported to have said:

    Kramer auto Pingback[…] actionscript, library AS3 で ZIP 解凍。GZIP はhttp://probertson.com/projects/gzipencoder/。 […]


  9. akhil is reported to have said:

    this library is working with desktop AIR application. But i want to use this library in web application flex. how can i do this

    thank you


  10. Paul is reported to have said:

    @akhil:
    Others have also commented on this, above. As I replied, it is theoretically possible to use the library in a Flash Player (browser) application now that the raw DEFLATE compression is supported in Flash Player. However, the refactoring work to support it turned out to be more complex than I thought so I haven’t had a chance to finish it up.

    Obviously there is interest in it, so I’ll try to take a look at it soon and see what I can do to get it working.


  11. Paul Robertson is reported to have said:

    For everyone who’s asked (and I’m surprised how many have), I’ve got a beta (barely tested) version of the library with support for Flash Player-only projects (no AIR dependencies). See the full post for details.


  12. Mark Lynch is reported to have said:

    Hi Paul,

    Thanks for the great piece of code - I’ve taken your new version and used it with Anirudh’s code (with some minor modification) to make a drop in replacement for HTTPService which will handle both gzip’d and non gzip’d content.

    http://www.learnosity.com/techblog/index.cfm/2009/3/19/More-of-AIR-Gzip-compression

    Great work.
    Thanks,
    Mark


  13. Joe Corner-Reeve is reported to have said:

    Hello guys,
    Is your compression function in actionscript 3?

    Wow! I think because we need high-level compression by function like WinRar, 7z or kgb compressing functions. How do i know about currect encoder by rar, 7z or kgb compressed files?
    Where do i find encodes from internet?

    I have problem of adobe air while my sample file will compressing onto compressed file. But adobe air application was killed by debug while compression process lose that long time.. :(

    I need processbar on panel like WinRar with process panel while compressor will to be final created compressed files?

    Thank you! Ragards, Joe Corne-Reeve


  14. Paul Robertson is reported to have said:

    @Joe:
    The compression is built into AIR/Flash Player, so it runs in native code, not in ActionScript. Other compression formats such as the ones you mention would either need to be included in the player or rewritten in ActionScript.

    Unfortunately, the compression and decompression run synchronously in Flash Player/AIR, so there’s no way to get progress notifications (or even run any other code) while they’re running.


  15. k.chandra shekar is reported to have said:

    hi paul

    I am trying to compress the files in flex app using flash player 10 but it is not working in fp10 give me exact solution how to compress files in flex web application development not in the air
    i neede so how to do pls help me the ways
    bye


  16. Gregor Rot is reported to have said:

    For flash player 10 that supports gzip comp/decomp, the only thing that needed to be changed in the code is:

    data.compress(…) -> data.inflate();
    data.uncompress(…) -> data.deflate();

    Gregor


  17. Flex to REST w/ GZip return | Flex Developer forums is reported to have said:

    Kramer auto Pingback[…] XML files using GZip (.NET supports this natively and I found an Open Source Library to load it http://probertson.com/projects/gzipencoder/).  The problem is that now that I am sending GZip data back from the REST application, the […]


  18. Matias is reported to have said:

    What about split compressed files?

    ie:
    encoder.compressToFile(source, destination, limitPerFile);

    Can I do this?

    Any idea?


  19. Paul Robertson is reported to have said:

    Matias,
    The library doesn’t support “split” compressed files. I based the library on the GZIP spec, and it doesn’t say anything about a standard way of splitting files (unless I missed it or they’ve added it in since then). If you know of a standard way of doing it, or you’ve seen another GZIP implementation that provides that support, let me know and I can try to research it and implement it. Otherwise, it doesn’t seem to make sense to implement that as a feature since other GZIP implementations wouldn’t be able to understand how to decompress the files.


  20. Adobe AIR SOAP WebService Compression « Norvinet's Blog is reported to have said:

    […] http://probertson.com/projects/gzipencoder/ […]


  21. Ross R is reported to have said:

    I am trying to implement this to compress an XML String which will be sent to JS via ExternalInterface, and then posted to a C# page.

    It isn’t working at the moment, because I don’t seem to be able to get a String representation of the compressed ByteArray. For some reason, the JS fires off an error as soon as I pass the byteArray string to it “unterminated string element” or some such.

    Any ideas how I can make this work for my purposes?


  22. Paul Robertson is reported to have said:

    Hi Ross,

    You can’t directly get a string representation of a ByteArray. (Well, you can try, but chances are some of the characters will be outside the normal character range.) One common way of string-encoding binary data is to convert the ByteArray to a Base64-encoded string. You would then need to decode it to binary again on your server.

    Flex SDK includes a Base64Encoder class that will do the Base64 encoding for you. You just pass the ByteArray to your Base64Encoder and then call toString() to get the Base64 string.


  23. HOW TO COMPRESS FILES AT THE CLIENT END IN ADOBE AIR : 93920 is reported to have said:

    […] http://probertson.com/projects/gzipencoder/ […]


  24. Carlos Bueno: A Dismal Guide to Bandwidth is reported to have said:

    Kramer auto Pingback[…] If your app sends largish amounts of data upstream (excluding images, which are already compressed), consider implementing client-side compression. It's possible to get 1.5:1 compression with a simple LZW+Base64 function; if you're willing to monkey with ActionScript you could probably do real gzip compression. […]

Add your comment





Comment notes

Please keep comments on topic. Comments that are inappropriate or offensive will be edited or removed.

Paragraphs and line breaks are automatically converted to HTML, and quotation marks are converted to “smart” quotes.

The following XHTML tags can be used: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> . All others will be removed.

Articles by Type

Articles by Topic

Random Reading

Currently...

Subscribe