authorgravatar for leroycepearson@geemili.xyzLeRoyce Pearson <leroycepearson@geemili.xyz> 2020-03-06 20:18:34-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-05-25 13:48:43-04:00
log86fe88bbcbbd14455ada878db75b387fb5f864fc
treed9f0441b176f027c98ce15e9dbe3d1f80075afb8
parent8c8813a5cfa710478614cbb022481f830f199bad

Use std.fs.base64_encoder in std.cache_hash


1 files changed, 6 insertions(+), 8 deletions(-)

lib/std/cache_hash.zig+6-8
...@@ -11,10 +11,8 @@ const Allocator = mem.Allocator;...@@ -11,10 +11,8 @@ const Allocator = mem.Allocator;
11const Buffer = @import("buffer.zig").Buffer;11const Buffer = @import("buffer.zig").Buffer;
12const os = @import("os.zig");12const os = @import("os.zig");
1313
14const base64_alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";14const base64_encoder = fs.base64_encoder;
15const base64_pad_char = '=';15const base64_decoder = fs.base64_decoder;
16const encoder = base64.Base64Encoder.init(base64_alphabet, base64_pad_char);
17const decoder = base64.Base64Decoder.init(base64_alphabet, base64_pad_char);
18const BIN_DIGEST_LEN = 32;16const BIN_DIGEST_LEN = 32;
1917
20pub const CacheHashFile = struct {18pub const CacheHashFile = struct {
...@@ -107,7 +105,7 @@ pub const CacheHash = struct {...@@ -107,7 +105,7 @@ pub const CacheHash = struct {
107105
108 const OUT_DIGEST_LEN = base64.Base64Encoder.calcSize(BIN_DIGEST_LEN);106 const OUT_DIGEST_LEN = base64.Base64Encoder.calcSize(BIN_DIGEST_LEN);
109 try self.b64_digest.resize(OUT_DIGEST_LEN);107 try self.b64_digest.resize(OUT_DIGEST_LEN);
110 encoder.encode(self.b64_digest.toSlice(), &bin_digest);108 base64_encoder.encode(self.b64_digest.toSlice(), &bin_digest);
111109
112 if (self.files.toSlice().len == 0 and !self.force_check_manifest) {110 if (self.files.toSlice().len == 0 and !self.force_check_manifest) {
113 try out_digest.resize(OUT_DIGEST_LEN);111 try out_digest.resize(OUT_DIGEST_LEN);
...@@ -166,7 +164,7 @@ pub const CacheHash = struct {...@@ -166,7 +164,7 @@ pub const CacheHash = struct {
166164
167 cache_hash_file.file_handle = fmt.parseInt(os.fd_t, file_handle_str, 10) catch return error.InvalidFormat;165 cache_hash_file.file_handle = fmt.parseInt(os.fd_t, file_handle_str, 10) catch return error.InvalidFormat;
168 cache_hash_file.stat.mtime = fmt.parseInt(i64, mtime_nsec_str, 10) catch return error.InvalidFormat;166 cache_hash_file.stat.mtime = fmt.parseInt(i64, mtime_nsec_str, 10) catch return error.InvalidFormat;
169 decoder.decode(&cache_hash_file.bin_digest, digest_str) catch return error.InvalidFormat;167 base64_decoder.decode(&cache_hash_file.bin_digest, digest_str) catch return error.InvalidFormat;
170168
171 if (file_path.len == 0) {169 if (file_path.len == 0) {
172 return error.InvalidFormat;170 return error.InvalidFormat;
...@@ -255,7 +253,7 @@ pub const CacheHash = struct {...@@ -255,7 +253,7 @@ pub const CacheHash = struct {
255253
256 const OUT_DIGEST_LEN = base64.Base64Encoder.calcSize(BIN_DIGEST_LEN);254 const OUT_DIGEST_LEN = base64.Base64Encoder.calcSize(BIN_DIGEST_LEN);
257 try out_digest.resize(OUT_DIGEST_LEN);255 try out_digest.resize(OUT_DIGEST_LEN);
258 encoder.encode(out_digest.toSlice(), &bin_digest);256 base64_encoder.encode(out_digest.toSlice(), &bin_digest);
259 }257 }
260258
261 pub fn write_manifest(self: *@This()) !void {259 pub fn write_manifest(self: *@This()) !void {
...@@ -268,7 +266,7 @@ pub const CacheHash = struct {...@@ -268,7 +266,7 @@ pub const CacheHash = struct {
268 defer contents.deinit();266 defer contents.deinit();
269267
270 for (self.files.toSlice()) |file| {268 for (self.files.toSlice()) |file| {
271 encoder.encode(encoded_digest.toSlice(), &file.bin_digest);269 base64_encoder.encode(encoded_digest.toSlice(), &file.bin_digest);
272 try contents.print("{} {} {} {}\n", .{ file.file_handle, file.stat.mtime, encoded_digest.toSlice(), file.path });270 try contents.print("{} {} {} {}\n", .{ file.file_handle, file.stat.mtime, encoded_digest.toSlice(), file.path });
273 }271 }
274272