Zig Requires Chilkat v11.0.0+
Zig
Unzip Encrypted Text into a String Variable
See more Zip Examples
Demonstrates how to open an encrypted .zip archive and unzip a text file directly into a string variable.Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const zip = try chilkat.Zip.init();
defer zip.deinit();
// Set the password required for decrypting.
zip.setDecryptPassword("myPassword");
zip.openZip("encrypted.zip") catch {
std.debug.print("{s}\n", .{try zip.getLastErrorText(alloc)});
return;
};
// Locate the file within the Zip to be unzipped into a string variable:
const entry = try chilkat.ZipEntry.init();
defer entry.deinit();
zip.entryMatching("*.csv", entry) catch {
std.debug.print("{s}\n", .{try zip.getLastErrorText(alloc)});
return;
};
// lineEndingBehavior:
// 0 = leave unchanged.
// 1 = convert all to bare LF's
// 2 = convert all to CRLF's
const line_ending_behavior = 0;
const src_charset = "utf-8";
const str_csv = try entry.unzipToString(alloc, line_ending_behavior, src_charset);
std.debug.print("{s}\n", .{str_csv});
}