diff options
| author | 2022-11-15 13:55:07 +0200 | |
|---|---|---|
| committer | 2022-11-15 13:55:07 +0200 | |
| commit | 33226c20c41e3fe2de3330b6692c90bc4818b119 (patch) | |
| tree | 4e66df2da513eb7270c1d0ebc23aef3e264099f8 /src/http.zig | |
| parent | Replace my zig-curl with zelda (diff) | |
| download | zup-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.zig | 23 |
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 @@ | |||
| 1 | const std = @import("std"); | ||
| 2 | const zelda = @import("zelda"); | ||
| 3 | |||
| 4 | const Allocator = std.mem.Allocator; | ||
| 5 | const 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 | ||
| 9 | pub 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 | } | ||