FZip Alpha Release: Create And Modify ZIP Archives

FZip has been around for some time now, and people seem to like it. However one feature has been asked for repeatedly: In addition to reading ZIP archive, people want to be able to create new (and modify existing) archives.

So i finally sat down this weekend and added that.

The code is not tested very well (it works for me but may not work for you) and has no ASDocs yet, so i release it as an alpha version, with the hope of massive bug feedback.. :)

Download: fzip_1_0_52_alpha.zip fzip_1_0_055.zip

New methods in class FZip:

  • addFile(name:String, date:Date, content:ByteArray)
  • addFileAt(index:uint, name:String, date:Date, content:ByteArray)
  • removeFileAt(index:uint)
  • serialize(stream:IDataOutput)

Sample code:

// Create file contents
var ba:ByteArray = new ByteArray();
ba.writeUTFBytes("Hello World!");
// Create ZIP archive and add file
var zip:FZip = new FZip();
zip.addFile("hello.txt", null, ba);
// Serialize ZIP into a new file
// (we use the Adobe AIR specific class FileStream here,
// but you can as well use ByteArray or anything that
// implements IDataOutput)
var file:File = File.applicationStorageDirectory;
file = file.resolvePath("hello.zip");
var stream:FileStream = new FileStream();
stream.open(file, FileMode.WRITE);
zip.serialize(stream);
stream.close();

16 Responses to “FZip Alpha Release: Create And Modify ZIP Archives”

  1. Moses Gunesch Says:

    This is such a great utility, thanks so much you guys. Really revolutionary stuff.

    Something that was pretty confusing was that the CompressionAlgorithm class seems to only be included in the AIR framework. I’m not sure why it’s in the flash.utils directory but not shipped with my installation of FlashCS3, Flex2, or Flex3. Also, the input for ByteArray.uncompress is different in AIR than the one shipped with the other products.

    I thought I’d mention this since I didn’t see it in any of your posts, or even in the official docs… It might be nice if you clued people in that AIR is a requirement if that’s the case, or perhaps there’s some update to the CS3/Flex3 frameworks that I don’t know about, but that too would be nice to mention…

    Anyway thank again, great work, this is an invaluable tool I can use right away on all of my current projects! :)

  2. Claus Wahlers Says:

    Moses, yes that was true for the alpha. This is no longer true for the (not yet really officially released) latest version (i hope). I’ll release the new version very very soon.

    In the meantime, please check out:
    http://codeazur.com.br/lab/fzip/download/fzip_1_0_055.zip
    Please let me know if you run into any problems with this one.

    Thanks for using FZip!
    Claus.

  3. Moses Gunesch Says:

    Thanks, those previous errors are gone now in the code. Your sample code above more or less works, once you change the smart quotes back to regular quotes and remove the parameter null from the line, zip.addFile(“hello.txt”, null, ba), which only accepts 2 parameters in your 1.0.055 version.

    I’m really chomping at the bit here, I can use this utility immediately as soon as it’s possible for me to create a zip file that works with it in any way! A standard OSX zip file gives the error, “Data descriptors are not supported” when you try to load it with FZip. I have no idea how to run a Python script by the way if that’s mandatory.

    Your code above does create a hello.txt file (awesome!), although I had to hunt to discover that it was saved in an obscure library subfolder. I assume that the next step would be to figure out some way to load in the files I want to add to the zip, serialize them into ByteArrays, so back to the books. That sounds like an app unto itself… am I supposed to program that?

    Anyway, if anyone could make this process just a tiny bit easier, or help me figure out how I can create an FZip-compatible ZIP from any set of existing files, in any way shape or form on OSX, I can put this thing to use right away!

    Thanks again and sorry to need hand-holding.

  4. Martin Legris Says:

    This looks amazing! Someone should send it to the Papervision 3d, because unless they’ve changed things, a few months ago they were loading 3ds max models straight in from files that could seriously use compression!!!

    Keep it up!

  5. Claus Wahlers Says:

    @Moses:

    Yes the new API extensions changed a bit as you noticed (the blog post is a bit out of sync here). The 1.0.055 archive contains ASDocs which are up to date though.

    As for the loading files, serializing into ByteArray, feeding that to FZip and writing out the generated ZIP file, yes, you are supposed to program that. :) Maybe i put together some better code examples for the release that illustrate the whole process.

    Concerning your data descriptor problem: FZip does not support ZIP files that contain data descriptors. This is a technical problem that lies buried deep down in the PKZip file format and the Flash APIs: In a nutshell, data descriptors are located at the end of a ZIP archive and contain the sizes of the contained files (it’s like a directory). FZip needs to know the size of contained files before parsing the corresponding entry though, so it can’t parse those kind of ZIP archives (and unfortunately the Python script doesn’t fix that). In a ZIP archive that does not contain data descriptors the size info is contained in the regular file entries, just the way FZip needs it.

    I am on Windows so i don’t really know what zip tools are available on Macs. All Windows zip tools i tested write archive without data descriptors. I also know of Mac users who successfully used FZip in the past, so you might want to check out some other zip tool if possible?

    Somebody should write a zip tool (based on FZip) in AIR one day.. ;)

    @Martin:

    Thanks! I am almost 100% positive that the Papervision 3D guys know of FZip and its benefits. I am not too familiar with the code base so i can’t really say if it makes sense to integrate FZip into PV3D. I have already seen PV3D demos that use FZip, btw.

  6. Moses Gunesch Says:

    Okay so, for anyone who wants to use FZip on the Mac, here’s how I finally got it to work:

    1. Setup: For the sake of this example, put a copy of the python fixer tool (included in FZip under tools) on your Desktop, along with a folder of files you want to zip up. Open Terminal. I’m not a command line guy myself so maybe there are better ways to do the next steps but they worked for me. (Terminal is in Applications/Utilities). Type in the word zip and hit return, this shows the list of options for zipping files. Finally, download and install Python, it’s a simple, normal installation with no catches.

    2. In Terminal, navigate to your desktop, like: cd /Users/moses/Desktop

    3. Create the zip directory, using this syntax but replace the names with whatever you want to call the zip and whatever the folder of files to zip is actually called: zip newZipFile.zip folderOfFiles/*

    (For a plain folder of files this is fine. There’s also an option -j that lets you exclude folders, and some other options for including subfolders recursively. FZip doesn’t mind folders, foldernames are readable in your code via a file’s filename property.)

    4. Check your Desktop to see if the zip is there, and try unzipping it to see if the files are in it. Last, apply the adler checksum fix which we copied to the desktop in step1, using the actual name of your zipfile of course: python fzip-prepare.py newZipFile.zip

    (You may see a warning about a deprecated something or other when you run the fix, which is okay.)

    Hope that helps someone out.

  7. Moses Gunesch Says:

    Hi Claus, and happy new year –

    I’m running into a gnarly FZip issue: Zip files do not seem to cache in browsers!

    This means that users have to wait for the same image series to download multiple times. We need to find a fix for this or FZip won’t be viable for our project.

    I’ve tried changing the extension to .jpg and .html, as well as removing the extension, to trick the browser into caching the files… none of these tricks seem to work. Is there some way we could manipulate the file header to force browser-caching?

    (By the way, on Mac Safari browser, the activity window shows an error every time I load an FZip file, unfortunately I can’t read the entire thing because that window’s view controls are locked, it reads “Operation Could Not Be Completed (WebKitErrorDo…” then gets truncated by the window. Not sure if it’s this failure to complete the load that is causing the lack of caching perhaps.)

  8. Claus Wahlers Says:

    Hi Moses, happy new year to you too!

    Unfortunately i don’t know how to help you with caching and that Safari error.. here, caching ZIPs works like a charm. I woudn’t know why this would fail, as we’re using URLStream to load ZIPs and caching should be enabled by default. Also if you look at the demo on the FZip homepage, the browser caches the file (at least here on Windows). Maybe it’s some setting on your server that prevents caching, or an issue with Flash and Safari?

  9. Moses Gunesch Says:

    thanks for the reply… i did not realize that trying to get this stuff to work on mac would be such a chore, i’ve spent hours on it and thought i finally had it working.

    it doesn’t cache in either safari or firefox and it’s not the server, everything else caches fine. i am using the step by step process of zipping the files then injecting the checksum using the mac command line. i’m sure it’s just some issue with the mac’s zip.

    i really wish you guys had access to a mac to look at this stuff, i don’t have a pc but it you are going to drive me to buy Windows just to get your utility to work.

  10. kondor Says:

    nice part of code :) is any possibility to add comment into .zip archive?

  11. Francis Potter Says:

    I need to load a zip file from the local filesystem in AIR. The docs on the web site show a loadBytes method.

    http://codeazur.com.br/lab/fzip/docs/

    But the latest release doesn’t include it.

    http://codeazur.com.br/lab/fzip/

    What happened to that method? Is there a way to use FZip with a local zip file?

  12. Francis Potter Says:

    Oh, never mind, I must have downloaded an older version by mistake.

  13. ishan Says:

    hi all……..
    i am new at flash so i am not getting how to use this ……..
    where should i put the fzip folder for using……

  14. neil Says:

    I just want to say that this is a fantastic bit of kit, especially when combined with air.

    simply awesome

  15. zlatan24 Says:

    I heard about not bad application-fix zip, is able to: repair encrypted data from ZIP archives, repair self-extracting (SFX) files, repair ZIP files larger than 2 GB, restore ZIP files from damaged media (floppy disks, CDs, DVDs, Zip drives, etc.), the ZIP file recovery tool can check file integrity, repair corrupted ZIP archives on the local area network, fix the Cannot open file: it does not appear to be a valid archive in ZIP archive error.

  16. Pwhndvve Says:

    Rimsky went look closer buy cytotec then announced daughters.

Leave a Reply