Skip to content

Commit 95324c9

Browse files
committed
fix: make xz decompression work
1 parent 802a8ac commit 95324c9

File tree

3 files changed

+24
-16
lines changed

3 files changed

+24
-16
lines changed

build.zig.zon

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
.version = "0.7.0",
44
.dependencies = .{
55
.zip = .{
6-
.url = "https://github.com/AMythicDev/zip.zig/archive/refs/tags/v0.3.0.tar.gz",
7-
.hash = "zip-0.3.0-eQGR_4tTAAAOUDb0yPv2-cdgLuXIrDsnRroGc9SLZ78p",
6+
.url = "https://github.com/AMythicDev/zip.zig/archive/refs/tags/v0.3.1.tar.gz",
7+
.hash = "zip-0.3.0-eQGR_5tRAADu6ull10KRa4sjIjAOoFl0jirVEp7uDbxr",
88
},
99
},
1010
.minimum_zig_version = "0.15.1",

src/install.zig

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,12 @@ pub fn download_tarball(alloc: Allocator, client: *Client, tb_url: []const u8, t
132132
const tbw_intf = &tb_writer.interface;
133133
while (tarball_size_d + dlnow.load(AtomicOrder.monotonic) <= total_size_d) {
134134
const len = try reader.readSliceShort(&buff);
135-
if (len == 0) {
136-
break;
137-
}
138135
_ = try tbw_intf.write(buff[0..len]);
139-
140136
_ = dlnow.fetchAdd(@floatFromInt(len), AtomicOrder.monotonic);
137+
138+
if (len < buff.len) {
139+
break;
140+
}
141141
}
142142
progress_thread.join();
143143
try tb_writer.end();
@@ -184,11 +184,15 @@ pub fn get_json_dslist(client: *Client) anyerror!JsonResponse {
184184
try req.?.sendBodiless();
185185
var response = try req.?.receiveHead(&.{});
186186

187-
var json_buff: [1024 * 100]u8 = undefined;
188-
const res_r = response.reader(&.{});
189-
const bytes_read = try res_r.readSliceShort(&json_buff);
187+
var tbuf: [1024]u8 = undefined;
188+
var dbuf: [std.compress.flate.max_window_len]u8 = undefined;
189+
var json_buf: [1024 * 100]u8 = undefined;
190+
var decomp = http.Decompress{ .none = undefined };
191+
192+
const res_r = response.readerDecompressing(&tbuf, &decomp, &dbuf);
193+
const bytes_read = try res_r.readSliceShort(&json_buf);
190194

191-
return JsonResponse{ .body = json_buff, .length = bytes_read };
195+
return JsonResponse{ .body = json_buf, .length = bytes_read };
192196
}
193197

194198
pub fn make_request(client: *Client, uri: std.Uri) ?Client.Request {
@@ -226,11 +230,11 @@ pub fn check_hash(hashstr: *const [64]u8, reader: *std.Io.Reader) !bool {
226230

227231
inline fn extract_xz(alloc: Allocator, dirs: CommonPaths, rel: Release, reader: *std.Io.Reader) !void {
228232
// HACK: Use the older interface until Zig upgrades this
229-
const r = reader.adaptToOldInterface();
230-
var xz = try std.compress.xz.decompress(alloc, r);
233+
const buff = try alloc.alloc(u8, 4096);
234+
var xz = try std.compress.xz.Decompress.init(reader, alloc, buff);
235+
defer alloc.free(xz.takeBuffer());
231236
const release_dir = try dirs.install_dir.makeOpenPath(try release_name(alloc, rel), .{});
232-
var adpt = xz.reader().adaptToNewApi(&.{});
233-
const intf = &adpt.new_interface;
237+
const intf = &xz.reader;
234238
try std.tar.pipeToFileSystem(release_dir, intf, .{ .strip_components = 1 });
235239
}
236240

src/update-self.zig

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,13 @@ fn read_github_releases_data(alloc: Allocator, client: *Client) !json.Parsed(jso
108108
req.?.extra_headers = &.{ http.Header{ .name = "Accept", .value = "application/vnd.github+json" }, http.Header{ .name = "X-GitHub-Api-Version", .value = "2022-11-28" } };
109109
try req.?.sendBodiless();
110110

111+
var tbuf: [1024]u8 = undefined;
112+
var dbuf: [std.compress.flate.max_window_len]u8 = undefined;
113+
var decomp = http.Decompress{ .none = undefined };
111114
var resp = try req.?.receiveHead(&.{});
112-
const body = resp.reader(&.{});
113115

114-
var json_reader = json.Reader.init(alloc, body);
116+
const res_r = resp.readerDecompressing(&tbuf, &decomp, &dbuf);
117+
118+
var json_reader = json.Reader.init(alloc, res_r);
115119
return try json.parseFromTokenSource(json.Value, alloc, &json_reader, .{});
116120
}

0 commit comments

Comments
 (0)