| ... | ... | @@ -2,11 +2,11 @@ const std = @import("std"); |
| 2 | 2 | const string = []const u8; |
| 3 | 3 | const range = @import("range").range; |
| 4 | 4 | |
| 5 | | pub fn fmtByteCountIEC(alloc: *std.mem.Allocator, b: u64) !string { |
| 5 | pub fn fmtByteCountIEC(alloc: std.mem.Allocator, b: u64) !string { |
| 6 | 6 | return try reduceNumber(alloc, b, 1024, "B", "KMGTPEZY"); |
| 7 | 7 | } |
| 8 | 8 | |
| 9 | | pub fn reduceNumber(alloc: *std.mem.Allocator, input: u64, comptime unit: u64, comptime base: string, comptime prefixes: string) !string { |
| 9 | pub fn reduceNumber(alloc: std.mem.Allocator, input: u64, comptime unit: u64, comptime base: string, comptime prefixes: string) !string { |
| 10 | 10 | if (input < unit) { |
| 11 | 11 | return std.fmt.allocPrint(alloc, "{d} {s}", .{ input, base }); |
| 12 | 12 | } |
| ... | ... | @@ -24,7 +24,7 @@ pub fn intToFloat(n: u64) f64 { |
| 24 | 24 | return @intToFloat(f64, n); |
| 25 | 25 | } |
| 26 | 26 | |
| 27 | | pub fn addSentinel(alloc: *std.mem.Allocator, comptime T: type, input: []const T, comptime sentinel: T) ![:sentinel]const T { |
| 27 | pub fn addSentinel(alloc: std.mem.Allocator, comptime T: type, input: []const T, comptime sentinel: T) ![:sentinel]const T { |
| 28 | 28 | var list = try std.ArrayList(T).initCapacity(alloc, input.len + 1); |
| 29 | 29 | try list.appendSlice(input); |
| 30 | 30 | try list.append(sentinel); |
| ... | ... | @@ -34,7 +34,7 @@ pub fn addSentinel(alloc: *std.mem.Allocator, comptime T: type, input: []const T |
| 34 | 34 | |
| 35 | 35 | const alphabet = "0123456789abcdefghijklmnopqrstuvwxyz"; |
| 36 | 36 | |
| 37 | | pub fn randomSlice(alloc: *std.mem.Allocator, rand: *const std.rand.Random, comptime T: type, len: usize) ![]T { |
| 37 | pub fn randomSlice(alloc: std.mem.Allocator, rand: *const std.rand.Random, comptime T: type, len: usize) ![]T { |
| 38 | 38 | var buf = try alloc.alloc(T, len); |
| 39 | 39 | var i: usize = 0; |
| 40 | 40 | while (i < len) : (i += 1) { |
| ... | ... | @@ -50,13 +50,13 @@ pub fn trimPrefix(in: string, prefix: string) string { |
| 50 | 50 | return in; |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | | pub fn base64EncodeAlloc(alloc: *std.mem.Allocator, input: string) !string { |
| 54 | | const base64 = std.base64.standard_encoder; |
| 53 | pub fn base64EncodeAlloc(alloc: std.mem.Allocator, input: string) !string { |
| 54 | const base64 = std.base64.standard.Encoder; |
| 55 | 55 | var buf = try alloc.alloc(u8, base64.calcSize(input.len)); |
| 56 | 56 | return base64.encode(buf, input); |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | | pub fn asciiUpper(alloc: *std.mem.Allocator, input: string) ![]u8 { |
| 59 | pub fn asciiUpper(alloc: std.mem.Allocator, input: string) ![]u8 { |
| 60 | 60 | var buf = try alloc.dupe(u8, input); |
| 61 | 61 | for (range(buf.len)) |_, i| { |
| 62 | 62 | buf[i] = std.ascii.toUpper(buf[i]); |
| ... | ... | @@ -110,7 +110,7 @@ pub fn FieldType(comptime T: type, comptime field: std.meta.FieldEnum(T)) type { |
| 110 | 110 | unreachable; |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | | pub fn fileList(alloc: *std.mem.Allocator, dir: std.fs.Dir) ![]string { |
| 113 | pub fn fileList(alloc: std.mem.Allocator, dir: std.fs.Dir) ![]string { |
| 114 | 114 | var list = std.ArrayList(string).init(alloc); |
| 115 | 115 | defer list.deinit(); |
| 116 | 116 | |
| ... | ... | @@ -123,7 +123,7 @@ pub fn fileList(alloc: *std.mem.Allocator, dir: std.fs.Dir) ![]string { |
| 123 | 123 | return list.toOwnedSlice(); |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | | pub fn dirSize(alloc: *std.mem.Allocator, dir: std.fs.Dir) !usize { |
| 126 | pub fn dirSize(alloc: std.mem.Allocator, dir: std.fs.Dir) !usize { |
| 127 | 127 | var res: usize = 0; |
| 128 | 128 | |
| 129 | 129 | var walk = try dir.walk(alloc); |
| ... | ... | @@ -157,7 +157,7 @@ pub const HashFn = enum { |
| 157 | 157 | sha3_512, |
| 158 | 158 | }; |
| 159 | 159 | |
| 160 | | pub fn hashFile(alloc: *std.mem.Allocator, dir: std.fs.Dir, sub_path: string, comptime algo: HashFn) !string { |
| 160 | pub fn hashFile(alloc: std.mem.Allocator, dir: std.fs.Dir, sub_path: string, comptime algo: HashFn) !string { |
| 161 | 161 | const file = try dir.openFile(sub_path, .{}); |
| 162 | 162 | defer file.close(); |
| 163 | 163 | const hash = std.crypto.hash; |