Zig Requires Chilkat v11.0.0+
Zig
Create a Zip Entirely in Memory
See more Zip Examples
Demonstrates how to create a .zip from in-memory byte data and strings, and to write the .zip to an in-memory image.Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
var success: bool = false;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const crypt = try chilkat.Crypt2.init();
defer crypt.deinit();
const zip = try chilkat.Zip.init();
defer zip.deinit();
success = if (zip.newZip("test.zip")) true else |_| false;
if (!success) {
std.debug.print("{s}\n", .{try zip.getLastErrorText(alloc)});
return;
}
// Add the bytes 0x00 0x01 0x02 0x03 ... 0x0F as a file in the .zip
const bd = try chilkat.BinData.init();
defer bd.deinit();
bd.appendEncoded("000102030405060708090A0B0C0D0E0F", "hex") catch {};
zip.addBd("binaryData.dat", bd) catch {};
// Add the string "Hello World!" to the .zip
zip.addString("helloWorld.txt", "Hello World!", "utf-8") catch {};
ERROR: Method not in the Zig package: Zip.WriteToMemory
ERROR: Method not in the Zig package: Zip.WriteToMemory
zip_file_in_memory = zip.ERROR();
// We could save these files to a file, and it is a valid .zip
const fac = try chilkat.FileAccess.init();
defer fac.deinit();
ERROR: Method not in the Zig package: FileAccess.WriteEntireFile
ERROR: Method not in the Zig package: FileAccess.WriteEntireFile
success = fac.ERROR();
if (!success) {
std.debug.print("{s}\n", .{try fac.getLastErrorText(alloc)});
return;
}
std.debug.print("Zip Created!\n", .{});
}