Requires: libzip (auto-installed via minks install zip)
#include "zip"
| Method | Args | Out | Description |
|---|---|---|---|
Zip:Open |
path |
Number | Open or create archive; returns handle. Throws ZipException on failure |
Zip:Close |
handle |
void | Write changes to disk and release handle |
Zip:Discard |
handle |
void | Close without saving changes |
Zip:AddFile |
handle, entryName, filePath |
Boolean | Add file from disk (read lazily at Close) |
Zip:AddText |
handle, entryName, content |
Boolean | Add a string as a zip entry |
Zip:AddDir |
handle, dirName |
Boolean | Add a directory entry |
Zip:Count |
handle |
Number | Number of entries in the archive |
Zip:Name |
handle, index |
String | Entry name at zero-based index |
Zip:Read |
handle, entryName |
String | Read entry contents as a string |
Zip:Extract |
handle, entryName, destPath |
Boolean | Extract entry to a file on disk |
Zip:Error |
handle |
String | Last error message, "" if none |
Throws ZipException on open failure. See Object — Exception.
Var:Number z;
Var:Boolean ok;
Var:String content;
Var:Number n;
try {
Zip:Open("archive.zip", z);
} catch (ZipException e) {
Konsol:Print("open failed: ${e.message}");
}
Zip:AddText(z, "hello.txt", "Hello from minks!", ok);
Zip:AddFile(z, "data/config.json", "config.json", ok);
Zip:AddDir(z, "logs/", ok);
Zip:Count(z, n);
Konsol:Print("entries: ${n}");
Zip:Close(z); // writes to disk
// Read back
Zip:Open("archive.zip", z);
Zip:Read(z, "hello.txt", content);
Konsol:Print(content); // Hello from minks!
Zip:Extract(z, "hello.txt", "extracted.txt", ok);
Zip:Close(z);
| Platform | Command |
|---|---|
| Debian/Ubuntu | sudo apt install libzip-dev |
| Fedora/RHEL | sudo dnf install libzip-devel |
| macOS | brew install libzip |
| MSYS2 MINGW64 | pacman -S mingw-w64-x86_64-libzip |
| MSYS2 UCRT64 | pacman -S mingw-w64-ucrt-x86_64-libzip |
| MSYS2 CLANG64 | pacman -S mingw-w64-clang-x86_64-libzip |
| MSYS2 CLANGARM64 | pacman -S mingw-w64-clang-aarch64-libzip |
The Makefile auto-detects via pkg-config.
make -C zip_plugin
// test_zip.ks — Zip plugin tests
// Run: minks --plugin ./kse_zip.dll test_zip.ks
// Creates "test_output.zip" in the working directory.
Konsol:Print("=== Zip plugin ===");
Var:Number z;
Var:Boolean ok;
Var:String s;
Var:Number n;
// ── Create + AddText ───────────────────────────────────────────────────────────
Konsol:Print("--- Create archive + AddText");
Zip:Open("test_output.zip", z);
Konsol:Print("handle : ${z}");
Zip:AddText(z, "hello.txt", "Hello from minks!", ok);
Konsol:Print("AddText hello.txt : ${ok}");
Zip:AddText(z, "notes/readme.txt", "This is a nested entry.", ok);
Konsol:Print("AddText notes/readme.txt : ${ok}");
Zip:AddText(z, "data.json", "{\"lang\":\"KonsolScript\",\"version\":1}", ok);
Konsol:Print("AddText data.json : ${ok}");
// ── AddDir ─────────────────────────────────────────────────────────────────────
Konsol:Print("--- AddDir");
Zip:AddDir(z, "emptydir/", ok);
Konsol:Print("AddDir emptydir/ : ${ok}");
// ── Count + Name before close ──────────────────────────────────────────────────
Konsol:Print("--- Count + Name");
Zip:Count(z, n);
Konsol:Print("entries : ${n}");
Zip:Name(z, 0, s);
Konsol:Print("entry[0] : ${s}");
Zip:Name(z, 1, s);
Konsol:Print("entry[1] : ${s}");
Zip:Name(z, 2, s);
Konsol:Print("entry[2] : ${s}");
Zip:Name(z, 3, s);
Konsol:Print("entry[3] : ${s}");
// ── Close (writes to disk) ─────────────────────────────────────────────────────
Konsol:Print("--- Close");
Zip:Close(z);
Konsol:Print("closed");
// ── Reopen + Read ──────────────────────────────────────────────────────────────
Konsol:Print("--- Reopen + Read");
Zip:Open("test_output.zip", z);
Konsol:Print("handle : ${z}");
Zip:Read(z, "hello.txt", s);
Konsol:Print("hello.txt : '${s}'");
Zip:Read(z, "notes/readme.txt", s);
Konsol:Print("notes/readme.txt : '${s}'");
Zip:Read(z, "data.json", s);
Konsol:Print("data.json : '${s}'");
// ── Extract ────────────────────────────────────────────────────────────────────
Konsol:Print("--- Extract");
Zip:Extract(z, "hello.txt", "extracted_hello.txt", ok);
Konsol:Print("Extract hello.txt : ${ok}");
// ── Error on missing entry ─────────────────────────────────────────────────────
Konsol:Print("--- missing entry");
Zip:Read(z, "doesnotexist.txt", s);
Konsol:Print("read result (expect empty) : '${s}'");
Zip:Error(z, s);
Konsol:Print("error : '${s}'");
// ── Discard ────────────────────────────────────────────────────────────────────
Konsol:Print("--- Discard (no changes written)");
Zip:AddText(z, "shouldnotappear.txt", "discarded", ok);
Zip:Discard(z);
Konsol:Print("discarded");
// ── Verify discard had no effect ───────────────────────────────────────────────
Konsol:Print("--- Verify discard");
Zip:Open("test_output.zip", z);
Zip:Count(z, n);
Konsol:Print("entries after discard (expect 4) : ${n}");
Zip:Close(z);
Konsol:Print("=== done ===");