diff options
author | 2023-01-24 21:57:25 +0200 | |
---|---|---|
committer | 2023-01-24 11:57:25 -0800 | |
commit | f43b67520032817877b5865173faf4b4c789089a (patch) | |
tree | ef0d87dfabdae75e456c0d81f1431449ec22d54b /src/libarchive | |
parent | e47fe2ca00a5d3cbf9710fedc1440aa25025317d (diff) | |
download | bun-f43b67520032817877b5865173faf4b4c789089a.tar.gz bun-f43b67520032817877b5865173faf4b4c789089a.tar.zst bun-f43b67520032817877b5865173faf4b4c789089a.zip |
support GitHub URLs as dependencies (#1875)
Diffstat (limited to 'src/libarchive')
-rw-r--r-- | src/libarchive/libarchive.zig | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/libarchive/libarchive.zig b/src/libarchive/libarchive.zig index df260125f..26eb5c5a3 100644 --- a/src/libarchive/libarchive.zig +++ b/src/libarchive/libarchive.zig @@ -468,6 +468,36 @@ pub const Archive = struct { } } + pub fn readFirstDirname( + file_buffer: []const u8, + ) !string { + var entry: *lib.archive_entry = undefined; + + var stream: BufferReadStream = undefined; + stream.init(file_buffer); + defer stream.deinit(); + _ = stream.openRead(); + var archive = stream.archive; + + return brk: { + while (true) { + const r = @intToEnum(Status, lib.archive_read_next_header(archive, &entry)); + + switch (r) { + Status.eof => break, + Status.retry => continue, + Status.failed, Status.fatal => return error.Fail, + else => { + var pathname: [:0]const u8 = std.mem.sliceTo(lib.archive_entry_pathname(entry).?, 0); + var tokenizer = std.mem.tokenize(u8, std.mem.span(pathname), std.fs.path.sep_str); + + if (tokenizer.next()) |name| break :brk name; + }, + } + } + }; + } + pub fn extractToDir( file_buffer: []const u8, dir_: std.fs.IterableDir, |