authorgravatar for chrisj.stephen2@gmail.comchristian-stephen <chrisj.stephen2@gmail.com> 2020-10-04 12:44:01-03:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-11-27 17:00:50-08:00
logabc729a5f9da9f4520079507404dd5d299209cba
treed955e38a7453410e876bc55b539092201dc1e858
parent9268972ff942f1d9db8fd0b89a8efe528d67e930

Add readAllArrayListAligned to Reader which can accept an arbitrary alignment


2 files changed, 10 insertions(+), 1 deletions(-)

lib/std/fs/file.zig+1-1
......@@ -394,7 +394,7 @@ pub const File = struct {
394394 var array_list = try std.ArrayListAligned(u8, alignment).initCapacity(allocator, initial_cap);
395395 defer array_list.deinit();
396396
397 self.reader().readAllArrayList(&array_list, max_bytes) catch |err| switch (err) {
397 self.reader().readAllArrayListAligned(alignment, &array_list, max_bytes) catch |err| switch (err) {
398398 error.StreamTooLong => return error.FileTooBig,
399399 else => |e| return e,
400400 };
lib/std/io/reader.zig+9
......@@ -57,6 +57,15 @@ pub fn Reader(
5757 /// If the number of bytes appended would exceed `max_append_size`, `error.StreamTooLong` is returned
5858 /// and the `std.ArrayList` has exactly `max_append_size` bytes appended.
5959 pub fn readAllArrayList(self: Self, array_list: *std.ArrayList(u8), max_append_size: usize) !void {
60 return self.readAllArrayListAligned(null, array_list, max_append_size);
61 }
62
63 pub fn readAllArrayListAligned(
64 self: Self,
65 comptime alignment: ?u29,
66 array_list: *std.ArrayListAligned(u8, alignment),
67 max_append_size: usize
68 ) !void {
6069 try array_list.ensureCapacity(math.min(max_append_size, 4096));
6170 const original_len = array_list.items.len;
6271 var start_index: usize = original_len;