imagine.zip

Description

The imagine.zip module (ImagineZip for AMS) provides you with functions for working with zip-files. This library can be used to extract or create zip files on disk and in memory. You could work with an archive and send it off without it ever touching the disk. Even adding files can be done completely in-memory, but also from files that exist on disk.

Downloads for version 0.3.1 (latest)

Changelog »

Windows

irsdk2

irsdk3

lua5.1

lua5.3

Creating Archives

This module can be used to create new zip files either on disk or in a memory buffer. The included zip.new_buffer function is capable of creating a dynamically sized buffer, so adding files to an archive in memory does not require you to manage the memory yourself.

Opening Archives

imagine.zip is also capable of reading existing archives, either from disk or a memory buffer. Using zip.new_buffer, you can also create read-only buffers that merely view a section of memory. Like this, you can have read-only access to zip files purely in memory. It also allows you to copy the memory you specify and turn it into a dynamically sized buffer again. Like this, you can open and modify archives.

Adding and Extracting

In this module a couple of functions allow you to add files from disk or memory and also extract to disk or memory. Aside from that, you can create directories in the archive. Using these features, encryption is also implemented. You can provide a password to the standard add_* and extract_* functions or set a default password to enable encryption.

local zip = require "imagine.zip"; -- no need for this if you use the ImagineZip AMS Plugin
local mem = require "imagine.mem"; -- no need for this if you use the ImagineMemory AMS Plugin

local archive, err = zip.read("my-data.zip");
if (not archive) then 
    error(err);
end

local stat, err = archive:stat("content.txt");
if (not stat) then
    error(err);
end

local buffer = mem.alloc(stat.size_uncompressed);
local success, read_size_or_error = archive:extract_memory("content.txt", buffer, stat.size_uncompressed);
if (not success) then
    error(read_size_or_error);
end

print("Read size: " .. read_size_or_error);
print("Content: " .. mem.u8str(buffer, stat.size_uncompressed));
mem.free(buffer);
archive:close();

Older Versions

There are multiple versions for this product. Older versions might be useful in the case of compatibility issues, but please do note that these versions are not supported anymore. The documentation for this product might also have been updated, we do not host the documentation for older versions.