Sample code for 30+ languages & platforms
Zig

Example: Http.ResumeDownloadBd method

Demonstrates the ResumeDownloadBd method.

Chilkat Zig Downloads

Zig
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 bd = try chilkat.BinData.init();
    defer bd.deinit();
    success = if (http.downloadBd("https://www.chilkatsoft.com/testData/hamlet_partial.xml", bd)) true else |_| false;
    if (!success) {
        std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
        return;
    }

    // Download the remainder of hamlet.xml.
    success = if (http.resumeDownloadBd("https://www.chilkatsoft.com/testData/hamlet.xml", bd)) 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
    std.debug.print("size of hamlet.xml: {d}\n", .{bd.getNumBytes()});

    std.debug.print("Success.\n", .{});
}