| ... | ... | @@ -1,61 +0,0 @@ |
| 1 | | const std = @import("std"); |
| 2 | | const string = []const u8; |
| 3 | | const gpa = std.heap.c_allocator; |
| 4 | | const range = @import("range").range; |
| 5 | | const zfetch = @import("zfetch"); |
| 6 | | const ansi = @import("ansi"); |
| 7 | | |
| 8 | | // |
| 9 | | // |
| 10 | | |
| 11 | | // https://www.thinkbroadband.com/download |
| 12 | | |
| 13 | | const Progress = struct { |
| 14 | | const Item = struct { |
| 15 | | max: usize, |
| 16 | | current: usize, |
| 17 | | done: bool, |
| 18 | | }; |
| 19 | | }; |
| 20 | | |
| 21 | | var progress: std.ArrayList(Progress.Item) = undefined; |
| 22 | | var left: usize = 0; |
| 23 | | |
| 24 | | pub fn execute(args: [][]u8) !void { |
| 25 | | _ = args; |
| 26 | | // progress = std.ArrayList(Progress.Item).init(gpa); |
| 27 | | // std.debug.print("\n", .{}); |
| 28 | | |
| 29 | | // for (range(3)) |_, i| { |
| 30 | | // try progress.append(.{ .max = 1, .current = 0, .done = false }); |
| 31 | | // left += 1; |
| 32 | | // try download("http://ipv4.download.thinkbroadband.com/100MB.zip", i); |
| 33 | | // } |
| 34 | | |
| 35 | | // while (left > 0) { |
| 36 | | // for (progress.items) |it, i| { |
| 37 | | // std.debug.print("{d}\t{d}\t{d}\t{d}%\n", .{ i, it.current, it.max, @divExact(it.current, it.max) }); |
| 38 | | // } |
| 39 | | // std.debug.print("\n", .{}); |
| 40 | | // } |
| 41 | | // for (progress.items) |it, i| { |
| 42 | | // std.debug.print("{d}\t{d}\t{d}\t{d}%\n", .{ i, it.current, it.max, @divExact(it.current, it.max) }); |
| 43 | | // } |
| 44 | | } |
| 45 | | |
| 46 | | fn download(url: string, index: usize) void { |
| 47 | | const req = zfetch.Request.init(gpa, url, null) catch {}; |
| 48 | | defer req.deinit(); |
| 49 | | |
| 50 | | req.do(.GET, null, null) catch {}; |
| 51 | | |
| 52 | | var buf: [std.mem.page_size]u8 = undefined; |
| 53 | | const r = req.reader(); |
| 54 | | while (true) { |
| 55 | | const len = r.readAll(&buf) catch {}; |
| 56 | | progress.items[index].current += len; |
| 57 | | if (len < buf.len) break; |
| 58 | | } |
| 59 | | progress.items[index].done = true; |
| 60 | | left -= 1; |
| 61 | | } |