Archive for category component

AS3 Zip Library Release

Here’s an ActionScript 3 based library for reading and writing zip files. I wrote this for another project I’m messing around with and thought I’d release it. I realize there’s already a useful library out there called FZip which is faster at uncompressing zip files as it uses the native uncompress method. However, it may require a script to preprocess a zip and inject Addler32 checksums which this library avoids by implementing a deflate compression decoder (inflater). If you are dealing with zips that only store files or run Python I recommend you check out FZip otherwise give this a try.

Features

  • Read or write zip files
  • Interface based on Java API (java.util.zip package)

Demo

This movie requires Flash Player 9

The source for this demo is available here.

Documentation

ASDoc Documentation

Download

The zip library is available as a swc component:
nochump-ziplib-105-dist.zip
The source files and documentation are also available:
nochump-ziplib-105-src.zip

nochump-ziplib-1.0-docs.zip

License

MIT

Usage

Below are examples of reading from a zip and writing to a new zip.

// read from a zip
import flash.utils.IDataInput;
import nochump.util.zip.*;

var loadedData:IDataInput;
// load a zip via URLStream or URLLoader using binary data format...
// create zip file
var zipFile:ZipFile = new ZipFile(loadedData);
for(var i:int = 0; i < zipFile.entries.length; i++) {
	var entry:ZipEntry = zipFile.entries[i];
	trace(entry.name);
	// extract the entry's data from the zip
	var data:ByteArray = zipFile.getInput(entry);
	trace(data.toString());
}
// write to a new zip

import flash.utils.ByteArray;
import nochump.util.zip.*;

// file info
var fileName:String = "helloworld.bin";
var fileData:ByteArray = new ByteArray();
fileData.writeUTF("Hello World!");
var zipOut:ZipOutput = new ZipOutput();
// Add entry to zip
var ze:ZipEntry = new ZipEntry(fileName);
zipOut.putNextEntry(ze);
zipOut.write(fileData);
zipOut.closeEntry();
// end the zip
zipOut.finish();
// access the zip data
var zipData:ByteArray = zipOut.byteArray;

Update: April 11, 2007

Updated the library to use Apollo’s ByteArray inflate/deflate native methods when running in the Apollo environment as pointed out by Ian Thomas. The current version is 1.0.1 built with acompc from the Apollo SDK. I’ve also tested the Apollo compatible swc under a regular as3 app and everything worked fine.

Update: July 29, 2007

Supports adding a zip file comment to ZipOutput. Use ZipOutput.comment =”Your comment here”.

Update: January 28, 2008

Changed license to LGPL.

Update: November 22, 2008

Changed license to MIT.

32 Comments