summaryrefslogtreecommitdiff
path: root/src/http.zig
diff options
context:
space:
mode:
authorGravatar Uko Kokņevičs2022-11-15 13:55:07 +0200
committerGravatar Uko Kokņevičs2022-11-15 13:55:07 +0200
commit33226c20c41e3fe2de3330b6692c90bc4818b119 (patch)
tree4e66df2da513eb7270c1d0ebc23aef3e264099f8 /src/http.zig
parentReplace my zig-curl with zelda (diff)
downloadzup-33226c20c41e3fe2de3330b6692c90bc4818b119.tar.gz
zup-33226c20c41e3fe2de3330b6692c90bc4818b119.tar.xz
zup-33226c20c41e3fe2de3330b6692c90bc4818b119.zip
Don't download the archive to a file
Diffstat (limited to 'src/http.zig')
-rw-r--r--src/http.zig23
1 files changed, 0 insertions, 23 deletions
diff --git a/src/http.zig b/src/http.zig
deleted file mode 100644
index bb3b3ac..0000000
--- a/src/http.zig
+++ /dev/null
@@ -1,23 +0,0 @@
1const std = @import("std");
2const zelda = @import("zelda");
3
4const Allocator = std.mem.Allocator;
5const File = std.fs.File;
6
7// TODO: zelda should be able to do this internally so I wouldn't have to allocate memory for the
8// file
9pub fn downloadToFile(allocator: Allocator, file: *File, url: []const u8) !void {
10 var response = try zelda.get(allocator, url);
11 defer response.deinit();
12
13 if (response.status_code.group() != .success) {
14 std.log.err("HTTP Error: {}", .{response.status_code});
15 return error.HttpError;
16 }
17
18 if (response.body) |body| {
19 try file.writer().writeAll(body);
20 } else {
21 std.log.warn("Downloaded nothing from {s}...", .{url});
22 }
23}