aboutsummaryrefslogtreecommitdiff
path: root/std/os
diff options
context:
space:
mode:
authorJosh Wolfe <thejoshwolfe@gmail.com>2017-11-17 23:42:21 -0700
committerJosh Wolfe <thejoshwolfe@gmail.com>2017-11-20 23:26:45 -0700
commita44283b0b2e585d7e15d7c8e6574411b75c12a0a (patch)
treeeb65022cc018de1061d44e030e4ce1287b991041 /std/os
parent339d48ac1558dcd1977574372becd21f7fc4a075 (diff)
downloadzig-a44283b0b2e585d7e15d7c8e6574411b75c12a0a.tar.gz
zig-a44283b0b2e585d7e15d7c8e6574411b75c12a0a.zip
rework std.base64 api
* rename decode to decodeExactUnsafe. * add decodeExact, which checks for invalid chars and padding. * add decodeWithIgnore, which also allows ignoring chars. * alphabets are supplied to the decoders with their char-to-index mapping already built, which enables it to be done at comptime. * all decode/encode apis except decodeWithIgnore require dest to be the exactly correct length. This is calculated by a calc function corresponding to each api. These apis no longer return the dest parameter. * for decodeWithIgnore, an exact size cannot be known a priori. Instead, a calc function gives an upperbound, and a runtime error is returned in case of overflow. decodeWithIgnore returns the number of bytes written to dest. closes #611
Diffstat (limited to 'std/os')
-rw-r--r--std/os/index.zig6
1 files changed, 3 insertions, 3 deletions
diff --git a/std/os/index.zig b/std/os/index.zig
index 34de6f3bbf..872564224c 100644
--- a/std/os/index.zig
+++ b/std/os/index.zig
@@ -622,7 +622,7 @@ pub fn symLinkPosix(allocator: &Allocator, existing_path: []const u8, new_path:
}
// here we replace the standard +/ with -_ so that it can be used in a file name
-const b64_fs_alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=";
+const b64_fs_alphabet_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
pub fn atomicSymLink(allocator: &Allocator, existing_path: []const u8, new_path: []const u8) -> %void {
if (symLink(allocator, existing_path, new_path)) {
@@ -639,7 +639,7 @@ pub fn atomicSymLink(allocator: &Allocator, existing_path: []const u8, new_path:
mem.copy(u8, tmp_path[0..], new_path);
while (true) {
%return getRandomBytes(rand_buf[0..]);
- _ = base64.encodeWithAlphabet(tmp_path[new_path.len..], rand_buf, b64_fs_alphabet);
+ base64.encode(tmp_path[new_path.len..], rand_buf, b64_fs_alphabet_chars, base64.standard_pad_char);
if (symLink(allocator, existing_path, tmp_path)) {
return rename(allocator, tmp_path, new_path);
} else |err| {
@@ -721,7 +721,7 @@ pub fn copyFileMode(allocator: &Allocator, source_path: []const u8, dest_path: [
defer allocator.free(tmp_path);
mem.copy(u8, tmp_path[0..], dest_path);
%return getRandomBytes(rand_buf[0..]);
- _ = base64.encodeWithAlphabet(tmp_path[dest_path.len..], rand_buf, b64_fs_alphabet);
+ base64.encode(tmp_path[dest_path.len..], rand_buf, b64_fs_alphabet_chars, base64.standard_pad_char);
var out_file = %return io.File.openWriteMode(tmp_path, mode, allocator);
defer out_file.close();