| ... | ... | @@ -884,6 +884,7 @@ pub fn Decompressor(comptime ReaderType: type) type { |
| 884 | 884 | s.inner_reader = new_reader; |
| 885 | 885 | s.step = nextBlock; |
| 886 | 886 | s.err = null; |
| 887 | s.nb = 0; |
| 887 | 888 | |
| 888 | 889 | s.dict.deinit(); |
| 889 | 890 | try s.dict.init(s.allocator, max_match_offset, new_dict); |
| ... | ... | @@ -898,6 +899,35 @@ const expectError = std.testing.expectError; |
| 898 | 899 | const io = std.io; |
| 899 | 900 | const testing = std.testing; |
| 900 | 901 | |
| 902 | test "confirm decompressor resets" { |
| 903 | var compressed = std.ArrayList(u8).init(std.testing.allocator); |
| 904 | defer compressed.deinit(); |
| 905 | |
| 906 | inline for (.{ |
| 907 | &[_]u8{ 0x5d, 0xc0, 0x21, 0x01, 0x00, 0x00, 0x00, 0x80, 0x20, 0xff, 0xaf, 0xa6, 0x4b, 0x03 }, |
| 908 | &[_]u8{ 0x55, 0xc1, 0x41, 0x0d, 0x00, 0x00, 0x00, 0x02, 0xa1, 0x94, 0x96, 0x34, 0x25, 0xef, 0x1b, 0x5f, 0x01 }, |
| 909 | }) |data| { |
| 910 | try compressed.writer().writeAll(data); |
| 911 | } |
| 912 | |
| 913 | var stream = std.io.fixedBufferStream(compressed.items); |
| 914 | var decomp = try decompressor(std.testing.allocator, stream.reader(), null); |
| 915 | defer decomp.deinit(); |
| 916 | |
| 917 | while (true) { |
| 918 | if (try stream.getPos() == try stream.getEndPos()) break; |
| 919 | |
| 920 | const buf = try decomp.reader().readAllAlloc(std.testing.allocator, 1024 * 100); |
| 921 | defer std.testing.allocator.free(buf); |
| 922 | |
| 923 | if (decomp.close()) |err| { |
| 924 | return err; |
| 925 | } |
| 926 | |
| 927 | try decomp.reset(stream.reader(), null); |
| 928 | } |
| 929 | } |
| 930 | |
| 901 | 931 | test "truncated input" { |
| 902 | 932 | const TruncatedTest = struct { |
| 903 | 933 | input: []const u8, |