Unzip implementation in pure Luau
Find a file
2025-03-11 16:42:05 +00:00
.github/workflows chore(actions): run all test suites, not just extract 2025-02-24 08:19:27 +00:00
.lune chore(lune): test runner not exiting with correct code 2025-02-23 20:15:07 +00:00
.vscode chore: init, the basics 2024-12-28 17:19:37 +00:00
.zed chore: zed editor configs 2025-02-23 14:27:08 +00:00
docs docs: update refs for d198f7f038 2025-02-23 18:56:23 +00:00
examples feat: add ZipEntry:unixMode() to get unix mode values as octals 2025-01-09 16:16:38 +00:00
lib refactor: use btest instead of band and ~= 2025-03-11 16:38:22 +00:00
scripts style: apply stylua formatter 2025-01-10 11:01:58 +00:00
tests fix: relax size checks and move test to edge case 2025-02-24 07:39:35 +00:00
.gitignore chore(gitignore): include zip test data 2025-01-07 13:43:15 +00:00
.luaurc chore: remove pkg alias 2025-01-06 06:08:34 +00:00
CHANGELOG.md chore(pkg): prepare for v0.1.3 2025-02-23 11:59:25 +00:00
dev.nix chore(nix): fix luau-lsp sha checksum 2025-03-11 16:42:05 +00:00
flake.lock chore: include nix configs for devenv 2025-02-09 11:05:58 +00:00
flake.nix chore(nix): apply formatting with nixpkgs-fmt 2025-02-09 17:16:31 +00:00
LICENSE.md chore(LICENSE): change copyright field 2024-12-30 11:12:45 +00:00
pesde.lock chore(pkg): prepare for v0.1.3 2025-02-23 11:59:25 +00:00
pesde.toml chore(pkg): prepare for v0.1.3 2025-02-23 11:59:25 +00:00
README.md chore(README): fix contribution section grammar mistake 2025-02-17 11:20:05 +05:30

luau-unzip

Discord Pesde Lune

A Luau library to unzip and extract files from ZIP archives. The implementation is based on the PKZip APPNOTE v6.3.9.

Features

  • Extract files from ZIP archives.
  • Supports INFLATE and STORE decompression methods.
  • Traverse and list archive contents.
  • Retrieve archive statistics (file count, directory count, total size) and metadata.

Usage

local fs = require("@lune/fs")
local zip = require("luau-unzip")

-- Read the ZIP file
local file = fs.readFile("test.zip")

-- Load the ZIP archive
local reader = zip.load(buffer.fromstring(file))

-- Print directory structure
print("Directory structure:")
reader:walk(function(entry, depth)
    local prefix = string.rep("  ", depth)
    local suffix = if not entry.isDirectory
        then string.format(" (%d bytes), content: %s", entry.size, reader:extract(entry, { type = "text" }) :: string)
        else ""
    print(prefix .. entry.name .. suffix)
end)

-- List children of root directory
print("\nChildren of `/`:")
local assets = reader:listDirectory("/")
for _, entry in assets do
    print(string.format("    %s - %s (%s)", entry.name, if entry.isDirectory then "DIR" else "FILE", entry.method))
end

-- Get archive statistics
local stats = reader:getStats()
print("\nArchive stats:")
print("Files:", stats.fileCount)
print("Directories:", stats.dirCount)
print("Total size:", stats.totalSize, "bytes")

MSLV (Minimum Supported Luau Version)

This library requires at least Luau 0.629 (specifically requires leading |, buffer built-in and idiv operator support).

Contributing

Contributions are heavily welcomed! We use Nix Flakes to manage a reproducible development environment. To get started, run exec nix develop -c $SHELL, after installing Nix. This is recommended for tests to be consistent, since we rely on InfoZIP implementations as sanity checks, although different distributions supply differently patched versions of it.

  • We utilize pesde for package management. Run pesde install to install all dependencies.
  • Before submitting a pull request, make sure you include comprehensive test cases for new features, and make sure all tests pass. Tests can be run with lune run tests. Refer to other test suites for examples of how to write your own tests.

License

This project is licensed under the MIT license.