| author | |
| committer | |
| log | 0cf756c80a4bc1b0459bc81bf8071891f12c3738 |
| tree | 552c0301b03a41a0294ffe30ad8f666381fdb125 |
| parent | b3457b31a1d1ea2c19c5d0b007c903d3e80add40 |
| signature |
12 files changed, 0 insertions(+), 360 deletions(-)
src/AnyReader.zig deleted-127| ... | ... | @@ -1,127 +0,0 @@ |
| 1 | const std = @import("std"); | |
| 2 | const string = []const u8; | |
| 3 | const extras = @import("./lib.zig"); | |
| 4 | const assert = std.debug.assert; | |
| 5 | ||
| 6 | pub const AnyReader = struct { | |
| 7 | readFn: *const fn (*anyopaque, []u8) anyerror!usize, | |
| 8 | state: *anyopaque, | |
| 9 | ||
| 10 | pub fn from(reader: anytype) AnyReader { | |
| 11 | const R = @TypeOf(reader); | |
| 12 | const ctx = reader.context; | |
| 13 | const Ctx = @TypeOf(ctx); | |
| 14 | switch (@typeInfo(Ctx)) { | |
| 15 | .pointer => { | |
| 16 | const S = struct { | |
| 17 | fn foo(s: *anyopaque, buffer: []u8) anyerror!usize { | |
| 18 | const r = R{ .context = @ptrCast(@alignCast(s)) }; | |
| 19 | return r.read(buffer); | |
| 20 | } | |
| 21 | }; | |
| 22 | return .{ | |
| 23 | .readFn = S.foo, | |
| 24 | .state = ctx, | |
| 25 | }; | |
| 26 | }, | |
| 27 | .@"struct" => switch (R) { | |
| 28 | std.fs.File.Reader => { | |
| 29 | const S = struct { | |
| 30 | fn foo(s: *anyopaque, buffer: []u8) anyerror!usize { | |
| 31 | const r = R{ .context = .{ .handle = @intCast(@intFromPtr(s)) } }; | |
| 32 | return r.read(buffer); | |
| 33 | } | |
| 34 | }; | |
| 35 | return .{ | |
| 36 | .readFn = S.foo, | |
| 37 | .state = @ptrFromInt(@as(usize, @intCast(ctx.handle))), | |
| 38 | }; | |
| 39 | }, | |
| 40 | else => @compileError(@typeName(R)), | |
| 41 | }, | |
| 42 | else => |v| @compileError(@typeName(R) ++ " , " ++ @tagName(v)), | |
| 43 | } | |
| 44 | } | |
| 45 | ||
| 46 | pub fn read(r: AnyReader, buffer: []u8) anyerror!usize { | |
| 47 | return r.readFn(r.state, buffer); | |
| 48 | } | |
| 49 | ||
| 50 | pub fn readByte(self: AnyReader) !u8 { | |
| 51 | var result: [1]u8 = undefined; | |
| 52 | const amt_read = try self.read(result[0..]); | |
| 53 | if (amt_read < 1) return error.EndOfStream; | |
| 54 | return result[0]; | |
| 55 | } | |
| 56 | ||
| 57 | pub fn readInt(self: AnyReader, comptime T: type, endian: std.builtin.Endian) !T { | |
| 58 | const bytes = try self.readBytesNoEof(@as(u16, @intCast((@as(u17, @typeInfo(T).Int.bits) + 7) / 8))); | |
| 59 | return std.mem.readInt(T, &bytes, endian); | |
| 60 | } | |
| 61 | ||
| 62 | pub fn readBytesNoEof(self: AnyReader, comptime num_bytes: usize) ![num_bytes]u8 { | |
| 63 | var bytes: [num_bytes]u8 = undefined; | |
| 64 | try self.readNoEof(&bytes); | |
| 65 | return bytes; | |
| 66 | } | |
| 67 | ||
| 68 | pub fn readNoEof(self: AnyReader, buf: []u8) !void { | |
| 69 | const amt_read = try self.readAll(buf); | |
| 70 | if (amt_read < buf.len) return error.EndOfStream; | |
| 71 | } | |
| 72 | ||
| 73 | pub fn readAll(self: AnyReader, buffer: []u8) !usize { | |
| 74 | return self.readAtLeast(buffer, buffer.len); | |
| 75 | } | |
| 76 | ||
| 77 | pub fn readAtLeast(self: AnyReader, buffer: []u8, len: usize) !usize { | |
| 78 | assert(len <= buffer.len); | |
| 79 | var index: usize = 0; | |
| 80 | while (index < len) { | |
| 81 | const amt = try self.read(buffer[index..]); | |
| 82 | if (amt == 0) break; | |
| 83 | index += amt; | |
| 84 | } | |
| 85 | return index; | |
| 86 | } | |
| 87 | ||
| 88 | pub fn readAllAlloc(self: AnyReader, allocator: std.mem.Allocator, max_size: usize) ![]u8 { | |
| 89 | var array_list = std.ArrayList(u8).init(allocator); | |
| 90 | defer array_list.deinit(); | |
| 91 | try self.readAllArrayList(&array_list, max_size); | |
| 92 | return try array_list.toOwnedSlice(); | |
| 93 | } | |
| 94 | ||
| 95 | pub fn readAllArrayList(self: AnyReader, array_list: *std.ArrayList(u8), max_append_size: usize) !void { | |
| 96 | return self.readAllArrayListAligned(null, array_list, max_append_size); | |
| 97 | } | |
| 98 | ||
| 99 | pub fn readAllArrayListAligned(self: AnyReader, comptime alignment: ?u29, array_list: *std.ArrayListAligned(u8, alignment), max_append_size: usize) !void { | |
| 100 | try array_list.ensureTotalCapacity(@min(max_append_size, 4096)); | |
| 101 | const original_len = array_list.items.len; | |
| 102 | var start_index: usize = original_len; | |
| 103 | while (true) { | |
| 104 | array_list.expandToCapacity(); | |
| 105 | const dest_slice = array_list.items[start_index..]; | |
| 106 | const bytes_read = try self.readAll(dest_slice); | |
| 107 | start_index += bytes_read; | |
| 108 | ||
| 109 | if (start_index - original_len > max_append_size) { | |
| 110 | array_list.shrinkAndFree(original_len + max_append_size); | |
| 111 | return error.StreamTooLong; | |
| 112 | } | |
| 113 | ||
| 114 | if (bytes_read != dest_slice.len) { | |
| 115 | array_list.shrinkAndFree(start_index); | |
| 116 | return; | |
| 117 | } | |
| 118 | ||
| 119 | // This will trigger ArrayList to expand superlinearly at whatever its growth rate is. | |
| 120 | try array_list.ensureTotalCapacity(start_index + 1); | |
| 121 | } | |
| 122 | } | |
| 123 | }; | |
| 124 | ||
| 125 | test { | |
| 126 | std.testing.refAllDecls(AnyReader); | |
| 127 | } |
src/dirSize.zig deleted-20| ... | ... | @@ -1,20 +0,0 @@ |
| 1 | const std = @import("std"); | |
| 2 | const string = []const u8; | |
| 3 | const extras = @import("./lib.zig"); | |
| 4 | const fileSize = extras.fileSize; | |
| 5 | ||
| 6 | pub fn dirSize(alloc: std.mem.Allocator, dir: std.fs.Dir) !u64 { | |
| 7 | var res: u64 = 0; | |
| 8 | ||
| 9 | var walk = try dir.walk(alloc); | |
| 10 | defer walk.deinit(); | |
| 11 | while (try walk.next()) |entry| { | |
| 12 | if (entry.kind != .file) continue; | |
| 13 | res += try fileSize(dir, entry.path); | |
| 14 | } | |
| 15 | return res; | |
| 16 | } | |
| 17 | ||
| 18 | test { | |
| 19 | std.testing.refAllDecls(@This()); | |
| 20 | } |
src/doesFileExist.zig deleted-17| ... | ... | @@ -1,17 +0,0 @@ |
| 1 | const std = @import("std"); | |
| 2 | const string = []const u8; | |
| 3 | const extras = @import("./lib.zig"); | |
| 4 | ||
| 5 | pub fn doesFileExist(dir: ?std.fs.Dir, fpath: []const u8) !bool { | |
| 6 | const file = (dir orelse std.fs.cwd()).openFile(fpath, .{}) catch |e| switch (e) { | |
| 7 | error.FileNotFound => return false, | |
| 8 | error.IsDir => return true, | |
| 9 | else => return e, | |
| 10 | }; | |
| 11 | defer file.close(); | |
| 12 | return true; | |
| 13 | } | |
| 14 | ||
| 15 | test { | |
| 16 | std.testing.refAllDecls(@This()); | |
| 17 | } |
src/doesFolderExist.zig deleted-21| ... | ... | @@ -1,21 +0,0 @@ |
| 1 | const std = @import("std"); | |
| 2 | const string = []const u8; | |
| 3 | const extras = @import("./lib.zig"); | |
| 4 | ||
| 5 | pub fn doesFolderExist(dir: ?std.fs.Dir, fpath: []const u8) !bool { | |
| 6 | const file = (dir orelse std.fs.cwd()).openFile(fpath, .{}) catch |e| switch (e) { | |
| 7 | error.FileNotFound => return false, | |
| 8 | error.IsDir => return true, | |
| 9 | else => return e, | |
| 10 | }; | |
| 11 | defer file.close(); | |
| 12 | const s = try file.stat(); | |
| 13 | if (s.kind != .directory) { | |
| 14 | return false; | |
| 15 | } | |
| 16 | return true; | |
| 17 | } | |
| 18 | ||
| 19 | test { | |
| 20 | std.testing.refAllDecls(@This()); | |
| 21 | } |
src/fileList.zig deleted-20| ... | ... | @@ -1,20 +0,0 @@ |
| 1 | const std = @import("std"); | |
| 2 | const string = []const u8; | |
| 3 | const extras = @import("./lib.zig"); | |
| 4 | ||
| 5 | pub fn fileList(alloc: std.mem.Allocator, dir: std.fs.Dir) ![]string { | |
| 6 | var list = std.ArrayList(string).init(alloc); | |
| 7 | defer list.deinit(); | |
| 8 | ||
| 9 | var walk = try dir.walk(alloc); | |
| 10 | defer walk.deinit(); | |
| 11 | while (try walk.next()) |entry| { | |
| 12 | if (entry.kind != .file) continue; | |
| 13 | try list.append(try alloc.dupe(u8, entry.path)); | |
| 14 | } | |
| 15 | return list.toOwnedSlice(); | |
| 16 | } | |
| 17 | ||
| 18 | test { | |
| 19 | std.testing.refAllDecls(@This()); | |
| 20 | } |
src/fileSize.zig deleted-14| ... | ... | @@ -1,14 +0,0 @@ |
| 1 | const std = @import("std"); | |
| 2 | const string = []const u8; | |
| 3 | const extras = @import("./lib.zig"); | |
| 4 | ||
| 5 | pub fn fileSize(dir: std.fs.Dir, sub_path: string) !u64 { | |
| 6 | const f = try dir.openFile(sub_path, .{}); | |
| 7 | defer f.close(); | |
| 8 | const s = try f.stat(); | |
| 9 | return s.size; | |
| 10 | } | |
| 11 | ||
| 12 | test { | |
| 13 | std.testing.refAllDecls(@This()); | |
| 14 | } |
src/hashFile.zig deleted-25| ... | ... | @@ -1,25 +0,0 @@ |
| 1 | const std = @import("std"); | |
| 2 | const string = []const u8; | |
| 3 | const extras = @import("./lib.zig"); | |
| 4 | const pipe = extras.pipe; | |
| 5 | ||
| 6 | pub fn hashFile(dir: std.fs.Dir, sub_path: string, comptime Algo: type) ![Algo.digest_length * 2]u8 { | |
| 7 | const file = try dir.openFile(sub_path, .{}); | |
| 8 | defer file.close(); | |
| 9 | var h = Algo.init(.{}); | |
| 10 | var out: [Algo.digest_length]u8 = undefined; | |
| 11 | try pipe(file.reader(), h.writer()); | |
| 12 | h.final(&out); | |
| 13 | var res: [Algo.digest_length * 2]u8 = undefined; | |
| 14 | var fbs = std.io.fixedBufferStream(&res); | |
| 15 | try std.fmt.format(fbs.writer(), "{x}", .{std.fmt.fmtSliceHexLower(&out)}); | |
| 16 | return res; | |
| 17 | } | |
| 18 | ||
| 19 | test { | |
| 20 | const tdir = std.testing.tmpDir(.{}).dir; | |
| 21 | try tdir.writeFile(.{ .sub_path = "yo.txt", .data = "hello" }); | |
| 22 | const A = std.crypto.hash.sha2.Sha256; | |
| 23 | const expected = "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824".*; | |
| 24 | try std.testing.expect(std.mem.eql(u8, &try hashFile(tdir, "yo.txt", A), &expected)); | |
| 25 | } |
src/lib.zig-22| ... | ... | @@ -14,13 +14,7 @@ pub const trimSuffixEnsure = @import("./trimSuffixEnsure.zig").trimSuffixEnsure; |
| 14 | 14 | pub const base64EncodeAlloc = @import("./base64EncodeAlloc.zig").base64EncodeAlloc; |
| 15 | 15 | pub const base64DecodeAlloc = @import("./base64DecodeAlloc.zig").base64DecodeAlloc; |
| 16 | 16 | pub const asciiUpper = @import("./asciiUpper.zig").asciiUpper; |
| 17 | pub const doesFileExist = @import("./doesFileExist.zig").doesFileExist; | |
| 18 | pub const doesFolderExist = @import("./doesFolderExist.zig").doesFolderExist; | |
| 19 | 17 | pub const sliceToInt = @import("./sliceToInt.zig").sliceToInt; |
| 20 | pub const fileList = @import("./fileList.zig").fileList; | |
| 21 | pub const fileSize = @import("./fileSize.zig").fileSize; | |
| 22 | pub const dirSize = @import("./dirSize.zig").dirSize; | |
| 23 | pub const hashFile = @import("./hashFile.zig").hashFile; | |
| 24 | 18 | pub const pipe = @import("./pipe.zig").pipe; |
| 25 | 19 | pub const countScalar = @import("./countScalar.zig").countScalar; |
| 26 | 20 | pub const sortBy = @import("./sortBy.zig").sortBy; |
| ... | ... | @@ -30,8 +24,6 @@ pub const containsString = @import("./containsString.zig").containsString; |
| 30 | 24 | pub const ensureFieldSubset = @import("./ensureFieldSubset.zig").ensureFieldSubset; |
| 31 | 25 | pub const fmtReplacer = @import("./fmtReplacer.zig").fmtReplacer; |
| 32 | 26 | pub const randomBytes = @import("./randomBytes.zig").randomBytes; |
| 33 | pub const readExpected = @import("./readExpected.zig").readExpected; | |
| 34 | pub const readBytes = @import("./readBytes.zig").readBytes; | |
| 35 | 27 | pub const FixedMaxBuffer = @import("./FixedMaxBuffer.zig").FixedMaxBuffer; |
| 36 | 28 | pub const hashBytes = @import("./hashBytes.zig").hashBytes; |
| 37 | 29 | pub const readType = @import("./readType.zig").readType; |
| ... | ... | @@ -41,7 +33,6 @@ pub const skipToBoundary = @import("./skipToBoundary.zig").skipToBoundary; |
| 41 | 33 | pub const is = @import("./is.zig").is; |
| 42 | 34 | pub const safeAdd = @import("./safeAdd.zig").safeAdd; |
| 43 | 35 | pub const safeAddWrap = @import("./safeAddWrap.zig").safeAddWrap; |
| 44 | pub const readBytesAlloc = @import("./readBytesAlloc.zig").readBytesAlloc; | |
| 45 | 36 | pub const nullifyS = @import("./nullifyS.zig").nullifyS; |
| 46 | 37 | pub const sliceTo = @import("./sliceTo.zig").sliceTo; |
| 47 | 38 | pub const matchesAll = @import("./matchesAll.zig").matchesAll; |
| ... | ... | @@ -53,7 +44,6 @@ pub fn assertLog(ok: bool, comptime message: string, args: anytype) void { |
| 53 | 44 | if (!ok) unreachable; // assertion failure |
| 54 | 45 | } |
| 55 | 46 | |
| 56 | pub const parse_json = @import("./parse_json.zig").parse_json; | |
| 57 | 47 | pub const isArrayOf = @import("./isArrayOf.zig").isArrayOf; |
| 58 | 48 | pub const parse_int = @import("./parse_int.zig").parse_int; |
| 59 | 49 | pub const parse_bool = @import("./parse_bool.zig").parse_bool; |
| ... | ... | @@ -68,7 +58,6 @@ pub const OneBiggerInt = @import("./OneBiggerInt.zig").OneBiggerInt; |
| 68 | 58 | pub const ReverseFields = @import("./ReverseFields.zig").ReverseFields; |
| 69 | 59 | pub const stringToEnum = @import("./stringToEnum.zig").stringToEnum; |
| 70 | 60 | pub const containsAggregate = @import("./containsAggregate.zig").containsAggregate; |
| 71 | pub const AnyReader = @import("./AnyReader.zig").AnyReader; | |
| 72 | 61 | pub const sum = @import("./sum.zig").sum; |
| 73 | 62 | pub const RingBuffer = @import("./RingBuffer.zig").RingBuffer; |
| 74 | 63 | pub const rawInt = @import("./rawInt.zig").rawInt; |
| ... | ... | @@ -117,13 +106,7 @@ test { |
| 117 | 106 | _ = @import("base64EncodeAlloc.zig"); |
| 118 | 107 | _ = @import("base64DecodeAlloc.zig"); |
| 119 | 108 | _ = @import("asciiUpper.zig"); |
| 120 | _ = @import("doesFileExist.zig"); | |
| 121 | _ = @import("doesFolderExist.zig"); | |
| 122 | 109 | _ = @import("sliceToInt.zig"); |
| 123 | _ = @import("fileList.zig"); | |
| 124 | _ = @import("fileSize.zig"); | |
| 125 | _ = @import("dirSize.zig"); | |
| 126 | _ = @import("hashFile.zig"); | |
| 127 | 110 | _ = @import("pipe.zig"); |
| 128 | 111 | _ = @import("countScalar.zig"); |
| 129 | 112 | _ = @import("sortBy.zig"); |
| ... | ... | @@ -133,8 +116,6 @@ test { |
| 133 | 116 | _ = @import("ensureFieldSubset.zig"); |
| 134 | 117 | _ = @import("fmtReplacer.zig"); |
| 135 | 118 | _ = @import("randomBytes.zig"); |
| 136 | _ = @import("readExpected.zig"); | |
| 137 | _ = @import("readBytes.zig"); | |
| 138 | 119 | _ = @import("FixedMaxBuffer.zig"); |
| 139 | 120 | _ = @import("hashBytes.zig"); |
| 140 | 121 | _ = @import("readType.zig"); |
| ... | ... | @@ -144,13 +125,11 @@ test { |
| 144 | 125 | _ = @import("is.zig"); |
| 145 | 126 | _ = @import("safeAdd.zig"); |
| 146 | 127 | _ = @import("safeAddWrap.zig"); |
| 147 | _ = @import("readBytesAlloc.zig"); | |
| 148 | 128 | _ = @import("nullifyS.zig"); |
| 149 | 129 | _ = @import("sliceTo.zig"); |
| 150 | 130 | _ = @import("matchesAll.zig"); |
| 151 | 131 | _ = @import("matchesAny.zig"); |
| 152 | 132 | _ = @import("opslice.zig"); |
| 153 | _ = @import("parse_json.zig"); | |
| 154 | 133 | _ = @import("isArrayOf.zig"); |
| 155 | 134 | _ = @import("parse_int.zig"); |
| 156 | 135 | _ = @import("parse_bool.zig"); |
| ... | ... | @@ -165,7 +144,6 @@ test { |
| 165 | 144 | _ = @import("ReverseFields.zig"); |
| 166 | 145 | _ = @import("stringToEnum.zig"); |
| 167 | 146 | _ = @import("containsAggregate.zig"); |
| 168 | _ = @import("AnyReader.zig"); | |
| 169 | 147 | _ = @import("sum.zig"); |
| 170 | 148 | _ = @import("RingBuffer.zig"); |
| 171 | 149 | _ = @import("rawInt.zig"); |
src/parse_json.zig deleted-7| ... | ... | @@ -1,7 +0,0 @@ |
| 1 | const std = @import("std"); | |
| 2 | const string = []const u8; | |
| 3 | const extras = @import("./lib.zig"); | |
| 4 | ||
| 5 | pub fn parse_json(alloc: std.mem.Allocator, input: string) !std.json.Parsed(std.json.Value) { | |
| 6 | return std.json.parseFromSlice(std.json.Value, alloc, input, .{}); | |
| 7 | } |
src/readBytes.zig deleted-26| ... | ... | @@ -1,26 +0,0 @@ |
| 1 | const std = @import("std"); | |
| 2 | const string = []const u8; | |
| 3 | const extras = @import("./lib.zig"); | |
| 4 | const assert = std.debug.assert; | |
| 5 | ||
| 6 | pub fn readBytes(reader: anytype, comptime len: usize) ![len]u8 { | |
| 7 | var bytes: [len]u8 = undefined; | |
| 8 | if (try reader.readAll(&bytes) != len) return error.EndOfStream; | |
| 9 | return bytes; | |
| 10 | } | |
| 11 | ||
| 12 | test { | |
| 13 | const array = [_]u8{ 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 }; | |
| 14 | var fba = std.io.fixedBufferStream(&array); | |
| 15 | const reader = fba.reader(); | |
| 16 | const res = try readBytes(reader, 2); | |
| 17 | try std.testing.expect(res.len == 2); | |
| 18 | try std.testing.expect(std.mem.eql(u8, &res, &.{ 9, 8 })); | |
| 19 | } | |
| 20 | ||
| 21 | test { | |
| 22 | const array = [_]u8{ 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 }; | |
| 23 | var fba = std.io.fixedBufferStream(&array); | |
| 24 | const reader = fba.reader(); | |
| 25 | try std.testing.expect(readBytes(reader, 13) == error.EndOfStream); | |
| 26 | } |
src/readBytesAlloc.zig deleted-30| ... | ... | @@ -1,30 +0,0 @@ |
| 1 | const std = @import("std"); | |
| 2 | const string = []const u8; | |
| 3 | const extras = @import("./lib.zig"); | |
| 4 | ||
| 5 | pub fn readBytesAlloc(reader: anytype, alloc: std.mem.Allocator, len: usize) ![]u8 { | |
| 6 | var list = try std.ArrayListUnmanaged(u8).initCapacity(alloc, len); | |
| 7 | errdefer list.deinit(alloc); | |
| 8 | list.appendNTimesAssumeCapacity(0, len); | |
| 9 | try reader.readNoEof(list.items[0..len]); | |
| 10 | return list.items; | |
| 11 | } | |
| 12 | ||
| 13 | test { | |
| 14 | const array = [_]u8{ 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 }; | |
| 15 | var fba = std.io.fixedBufferStream(&array); | |
| 16 | const reader = fba.reader(); | |
| 17 | const alloc = std.testing.allocator; | |
| 18 | const res = try readBytesAlloc(reader, alloc, 2); | |
| 19 | defer alloc.free(res); | |
| 20 | try std.testing.expect(res.len == 2); | |
| 21 | try std.testing.expect(std.mem.eql(u8, res, &.{ 9, 8 })); | |
| 22 | } | |
| 23 | ||
| 24 | test { | |
| 25 | const array = [_]u8{ 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 }; | |
| 26 | var fba = std.io.fixedBufferStream(&array); | |
| 27 | const reader = fba.reader(); | |
| 28 | const alloc = std.testing.allocator; | |
| 29 | try std.testing.expect(readBytesAlloc(reader, alloc, 11) == error.EndOfStream); | |
| 30 | } |
src/readExpected.zig deleted-31| ... | ... | @@ -1,31 +0,0 @@ |
| 1 | const std = @import("std"); | |
| 2 | const string = []const u8; | |
| 3 | const extras = @import("./lib.zig"); | |
| 4 | ||
| 5 | pub fn readExpected(reader: anytype, expected: []const u8) !bool { | |
| 6 | for (expected) |item| { | |
| 7 | const actual = try reader.readByte(); | |
| 8 | if (actual != item) { | |
| 9 | return false; | |
| 10 | } | |
| 11 | } | |
| 12 | return true; | |
| 13 | } | |
| 14 | ||
| 15 | test { | |
| 16 | const array = [_]u8{ 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 }; | |
| 17 | var fba = std.io.fixedBufferStream(&array); | |
| 18 | try std.testing.expect(try readExpected(fba.reader(), &.{ 9, 8, 7, 6 })); | |
| 19 | } | |
| 20 | ||
| 21 | test { | |
| 22 | const array = [_]u8{ 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 }; | |
| 23 | var fba = std.io.fixedBufferStream(&array); | |
| 24 | try std.testing.expect(!try readExpected(fba.reader(), &.{ 1, 2, 3 })); | |
| 25 | } | |
| 26 | ||
| 27 | test { | |
| 28 | const array = [_]u8{ 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 }; | |
| 29 | var fba = std.io.fixedBufferStream(&array); | |
| 30 | try std.testing.expect(try readExpected(fba.reader(), &.{})); | |
| 31 | } |