authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-04-02 21:46:34 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-04-02 21:46:34 -07:00
logb47e61c4f05e895fec868252b3a23c5111b0cd10
treedc2c2c19a545e8967817b8e13b1addad5ebac883
parentd34ac633f0a0af8d348b66a38e7497d031f027b1

add readBytesAlloc


1 files changed, 9 insertions(+), 0 deletions(-)

src/lib.zig+9
...@@ -439,3 +439,12 @@ pub fn safeAdd(a: anytype, b: anytype) @TypeOf(a) {...@@ -439,3 +439,12 @@ pub fn safeAdd(a: anytype, b: anytype) @TypeOf(a) {
439 }439 }
440 return a - @intCast(@TypeOf(a), -b);440 return a - @intCast(@TypeOf(a), -b);
441}441}
442
443pub fn readBytesAlloc(reader: anytype, alloc: std.mem.Allocator, len: usize) ![]u8 {
444 var list = std.ArrayListUnmanaged(u8){};
445 try list.ensureTotalCapacityPrecise(alloc, len);
446 errdefer list.deinit(alloc);
447 list.appendNTimesAssumeCapacity(0, len);
448 try reader.readNoEof(list.items[0..len]);
449 return list.items;
450}