Zig
Zig
Example: Http.ResumeDownload method
Demonstrates theResumeDownload method.
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;
const http = try chilkat.Http.init();
defer http.deinit();
http.setKeepResponseBody(true);
// To demonstrate resuming a download, we've created a file on the chilkatsoft.com
// web server that contains the first 82,379 bytes of the full 279,658 bytes of the hamlet.xml file.
// We'll first download the partial file, and pretend it was a previous incomplete attempt to download the entire file.
const local_file_path = "c:/temp/qa_output/hamlet.xml";
success = if (http.download("https://www.chilkatsoft.com/testData/hamlet_partial.xml", local_file_path)) true else |_| false;
if (!success) {
std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
return;
}
// Download the remainder of hamlet.xml.
success = if (http.resumeDownload("https://www.chilkatsoft.com/testData/hamlet.xml", local_file_path)) true else |_| false;
const status_code = http.getLastStatus();
if (!success) {
if (status_code == 0) {
// Unable to either send the request or get the response.
std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
} else {
// We got a response, but the status code was not in the 200s
std.debug.print("Response status code: {d}\n", .{status_code});
// Examine the response body.
std.debug.print("Response body:\n", .{});
std.debug.print("{s}\n", .{try http.getLastResponseBody(alloc)});
}
std.debug.print("Download failed.\n", .{});
} else {
std.debug.print("Download success, response status = {d}\n", .{status_code});
}
// The hamlet.xml file should be 279,658 bytes
const fac = try chilkat.FileAccess.init();
defer fac.deinit();
std.debug.print("size of hamlet.xml: {d}\n", .{fac.fileSize(local_file_path)});
std.debug.print("Success.\n", .{});
}