Complete b64Encoder.encode() method (requires testing)
This commit is contained in:
parent
08134db66b
commit
b9f798003b
28
src/root.zig
28
src/root.zig
@ -208,8 +208,32 @@ pub const b64Encoder = struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn encode(self: Self) !void {
|
pub fn encode(self: Self) !void {
|
||||||
_ = self;
|
var len = 12;
|
||||||
// todo
|
const buf: [12]u8 = undefined;
|
||||||
|
while (len == 12) {
|
||||||
|
len = try self.reader.readAll(buf);
|
||||||
|
if (len == 12) {
|
||||||
|
const obuf: [16]u8 = undefined;
|
||||||
|
try self.alphabet.encodeChunksVectored(buf, &obuf);
|
||||||
|
try self.writer.writeAll(obuf);
|
||||||
|
} else {
|
||||||
|
for ([4]usize{ 0, 2, 5, 8 }) |start| {
|
||||||
|
const end = start + 3;
|
||||||
|
const ibuf: [3]u8 = buf[start..end];
|
||||||
|
var obuf: [4]u8 = undefined;
|
||||||
|
if (start == len - 1) {
|
||||||
|
break;
|
||||||
|
} else if (end <= len - 1) {
|
||||||
|
self.alphabet.encodeChunk(ibuf, 3, &obuf);
|
||||||
|
try self.writer.writeAll(obuf);
|
||||||
|
} else {
|
||||||
|
self.alphabet.encodeChunk(ibuf, len - 1 - start, &obuf);
|
||||||
|
try self.writer.writeAll(obuf);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user