Zig
Zig
Split File into Chunks
Demonstrates how to split a file into chunks.Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
const fac = try chilkat.FileAccess.init();
defer fac.deinit();
// Any type of file may be split. It doesn't matter if it's
// a binary file or a text file.
const file_to_split = "qa_data/hamlet.xml";
const part_prefix = "hamlet";
const part_extension = "part";
const max_chunk_size = 50000;
const dest_dir_path = "qa_output";
// Splits hamlet.xml into hamlet1.part, hamlet2.part, ...
// Output files are written to the current working directory.
// Each chunk will be 50000 bytes except for the last which
// will be the remainder.
if (fac.splitFile(file_to_split, part_prefix, part_extension, max_chunk_size, dest_dir_path)) {
std.debug.print("Success.\n", .{});
} else |_| {
std.debug.print("{s}\n", .{try fac.getLastErrorText(alloc)});
}
}