| ... | ... | @@ -33,9 +33,11 @@ pub fn GzipStream(comptime ReaderType: type) type { |
| 33 | 33 | read_amt: usize, |
| 34 | 34 | |
| 35 | 35 | info: struct { |
| 36 | extra: ?[]const u8, |
| 36 | 37 | filename: ?[]const u8, |
| 37 | 38 | comment: ?[]const u8, |
| 38 | 39 | modification_time: u32, |
| 40 | operating_system: u8, |
| 39 | 41 | }, |
| 40 | 42 | |
| 41 | 43 | fn init(allocator: mem.Allocator, source: ReaderType) !Self { |
| ... | ... | @@ -59,33 +61,27 @@ pub fn GzipStream(comptime ReaderType: type) type { |
| 59 | 61 | // Operating system where the compression took place |
| 60 | 62 | const OS = header[9]; |
| 61 | 63 | _ = XFL; |
| 62 | | _ = OS; |
| 63 | 64 | |
| 64 | | if (FLG & FEXTRA != 0) { |
| 65 | | // Skip the extra data, we could read and expose it to the user |
| 66 | | // if somebody needs it. |
| 65 | const extra = if (FLG & FEXTRA != 0) blk: { |
| 67 | 66 | const len = try source.readIntLittle(u16); |
| 68 | | try source.skipBytes(len, .{}); |
| 69 | | } |
| 70 | | |
| 71 | | var filename: ?[]const u8 = null; |
| 72 | | if (FLG & FNAME != 0) { |
| 73 | | filename = try source.readUntilDelimiterAlloc( |
| 74 | | allocator, |
| 75 | | 0, |
| 76 | | max_string_len, |
| 77 | | ); |
| 78 | | } |
| 67 | const tmp_buf = try allocator.alloc(u8, len); |
| 68 | errdefer allocator.free(tmp_buf); |
| 69 | |
| 70 | try source.readNoEof(tmp_buf); |
| 71 | break :blk tmp_buf; |
| 72 | } else null; |
| 73 | errdefer if (extra) |p| allocator.free(p); |
| 74 | |
| 75 | const filename = if (FLG & FNAME != 0) |
| 76 | try source.readUntilDelimiterAlloc(allocator, 0, max_string_len) |
| 77 | else |
| 78 | null; |
| 79 | 79 | errdefer if (filename) |p| allocator.free(p); |
| 80 | 80 | |
| 81 | | var comment: ?[]const u8 = null; |
| 82 | | if (FLG & FCOMMENT != 0) { |
| 83 | | comment = try source.readUntilDelimiterAlloc( |
| 84 | | allocator, |
| 85 | | 0, |
| 86 | | max_string_len, |
| 87 | | ); |
| 88 | | } |
| 81 | const comment = if (FLG & FCOMMENT != 0) |
| 82 | try source.readUntilDelimiterAlloc(allocator, 0, max_string_len) |
| 83 | else |
| 84 | null; |
| 89 | 85 | errdefer if (comment) |p| allocator.free(p); |
| 90 | 86 | |
| 91 | 87 | if (FLG & FHCRC != 0) { |
| ... | ... | @@ -102,7 +98,9 @@ pub fn GzipStream(comptime ReaderType: type) type { |
| 102 | 98 | .info = .{ |
| 103 | 99 | .filename = filename, |
| 104 | 100 | .comment = comment, |
| 101 | .extra = extra, |
| 105 | 102 | .modification_time = MTIME, |
| 103 | .operating_system = OS, |
| 106 | 104 | }, |
| 107 | 105 | .read_amt = 0, |
| 108 | 106 | }; |
| ... | ... | @@ -110,6 +108,8 @@ pub fn GzipStream(comptime ReaderType: type) type { |
| 110 | 108 | |
| 111 | 109 | pub fn deinit(self: *Self) void { |
| 112 | 110 | self.inflater.deinit(); |
| 111 | if (self.info.extra) |extra| |
| 112 | self.allocator.free(extra); |
| 113 | 113 | if (self.info.filename) |filename| |
| 114 | 114 | self.allocator.free(filename); |
| 115 | 115 | if (self.info.comment) |comment| |