Zig
Zig
Wasabi Download String
See more Wasabi Examples
Demonstrates how to download a text Wasabi object to 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 assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const http = try chilkat.Http.init();
defer http.deinit();
// Insert your access key here:
http.setAwsAccessKey("access-key");
// Insert your secret key here:
http.setAwsSecretKey("secret-key");
// Use the endpoint matching the bucket's region.
http.setAwsEndpoint("s3.us-west-1.wasabisys.com");
const bucket_name = "chilkattest";
const object_name = "orchard.json";
// This is the byte representation of the text file downloaded from Wasabi.
// It must be specified to allow Chilkat to correctly interpret the bytes as characters.
const charset = "utf-8";
const file_contents = http.s3DownloadString(alloc, bucket_name, object_name, charset) catch "";
if (!http.getLastMethodSuccess()) {
std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
} else {
std.debug.print("{s}\n", .{file_contents});
std.debug.print("Success.\n", .{});
}
}