Basic usage

NOTE: The following example applies to targets that have access to the computer file system for file loading/saving (neko/cpp/php etc). For flash usage, have a look here:

Creating a zip file

Let's say that we want to create a zip file with one text file items inside: textfile.txt with the content of "Hello zip!".

1. Creating a zip file entry

Each of the zip file items is represented by a, so we start with creating that entry out of the "Hello zip!" string in the following way:
var string = "Hello zip!"; 
// Convert the string to bytes
var bytes = Bytes.ofString(string); 
// Create a zip entry for the bytes:
var =  
    fileName : "path/to/textfile.txt", // <- This is the internal zip file folder structure
    fileSize : bytes.length,
    fileTime :,
    compressed : false,
    dataSize : 0,
    data : bytes,
    crc32 :,
    extraFields : new List()

Please note that we can freely create the internal directory structure of our zip file by defining the desired path to the content file.

2. Creating a list of zip entries

Now we have create a single file zip entry item. We can create as many entries as we like. The entries should then be added to a list of entries:
// Create a list of entries
var entries:List<> = new List();
// Add our text data entry:
// Add as many entries as you like...
// ...

3. Saving the zip file

Now we can save it all to a zip file by using a to write to a BytesOutput stream:
// Write our entries to a BytesOutput stream using            
var bytesOutput = new BytesOutput();
var writer = new;
// Grab the zipped file from the output stream
var zipfileBytes = bytesOutput.getBytes();
// Save the zipped file to disc
var file = File.write("", true);

Reading a zip file

Here's how we can read the content from our newly created

4. Grabbing the list of entries out of the zip file

We start by reading the zip file and let the get our entries out of it:
// Read our zip file and get the bytes into a BytesInput stream
var zipfileBytes = File.getBytes("");
var bytesInput = new BytesInput(zipfileBytes);
// use a to grab the zip entries
var reader = new;
var entries:List<> =;        

As a result we have the same kind of list of entries as we saw in step 2 above.

5. Grabbing the data out of the zip entry

Now we can simply iterate our list of entries to search for the entry filename that we want to extract.
In step 1. above, we saved our string with the internal entry filename path/to/textfile.txt, so we have to search for this one among the entry filenames.
Here's a simplistic way of doing it:
var searchEntryFileName = "path/to/textfile.txt";
for (entry in entries ) {
    if (entry.fileName == searchEntryFileName) {
        // Get the bytes out of the entry and uncompress them
        var bytes:Bytes =;
        // Convert the bytes to a string
        var string = bytes.toString();
        // Should trace "Hello zip!"

version #15316, modified 2012-08-11 10:55:39 by ncannasse