Small changed & fixes
This commit is contained in:
+2
-2
@@ -69,9 +69,9 @@ pub fn extract(self: *Archive, alloc: std.mem.Allocator, io: Io, ext_loc: []cons
|
|||||||
self.super,
|
self.super,
|
||||||
);
|
);
|
||||||
|
|
||||||
// TODO: use single & multi respectively.
|
if (options.single_threaded)
|
||||||
|
|
||||||
return Decompress.single(alloc, io, self.map.memory, self.super, root_inode, ext_loc, options);
|
return Decompress.single(alloc, io, self.map.memory, self.super, root_inode, ext_loc, options);
|
||||||
|
return Decompress.multi(alloc, io, self.map.memory, self.super, root_inode, ext_loc, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Superblock
|
// Superblock
|
||||||
|
|||||||
+25
-23
@@ -6,6 +6,7 @@ const Directory = @import("dir.zig");
|
|||||||
const MetadataReader = @import("utils/meta.zig");
|
const MetadataReader = @import("utils/meta.zig");
|
||||||
const Options = @import("options.zig");
|
const Options = @import("options.zig");
|
||||||
const DataReader = @import("utils/data_reader.zig");
|
const DataReader = @import("utils/data_reader.zig");
|
||||||
|
const Decompress = @import("utils/decompress.zig");
|
||||||
const Super = @import("archive.zig").Super;
|
const Super = @import("archive.zig").Super;
|
||||||
|
|
||||||
const File = @This();
|
const File = @This();
|
||||||
@@ -86,19 +87,30 @@ pub fn open(self: File, alloc: std.mem.Allocator, filepath: []const u8) !File {
|
|||||||
defer dir.deinit(alloc);
|
defer dir.deinit(alloc);
|
||||||
|
|
||||||
var entries = dir.entries;
|
var entries = dir.entries;
|
||||||
|
var idx: usize = undefined;
|
||||||
|
|
||||||
while (entries.len > 1) {
|
while (entries.len > 1) {
|
||||||
const idx = entries.len / 2;
|
idx = entries.len / 2;
|
||||||
const val = entries[idx];
|
const val = entries[idx];
|
||||||
|
|
||||||
switch (std.mem.order(u8, first_element, val.name)) {
|
switch (std.mem.order(u8, first_element, val.name)) {
|
||||||
.eq => {
|
.eq => break,
|
||||||
if (final) {
|
.lt => entries = entries[0..idx],
|
||||||
|
.gt => entries = entries[idx..],
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!std.mem.eql(u8, first_element, entries[0].name))
|
||||||
|
return error.NotFound;
|
||||||
|
idx = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!final) break :blk entries[idx];
|
||||||
|
|
||||||
const inode: Inode = try .readLocation(
|
const inode: Inode = try .readLocation(
|
||||||
alloc,
|
alloc,
|
||||||
self.data,
|
self.data,
|
||||||
val.start,
|
entries[idx].start,
|
||||||
val.offset,
|
entries[idx].offset,
|
||||||
self.super,
|
self.super,
|
||||||
);
|
);
|
||||||
errdefer inode.deinit(alloc);
|
errdefer inode.deinit(alloc);
|
||||||
@@ -110,17 +122,8 @@ pub fn open(self: File, alloc: std.mem.Allocator, filepath: []const u8) !File {
|
|||||||
.super = self.super,
|
.super = self.super,
|
||||||
|
|
||||||
.inode = inode,
|
.inode = inode,
|
||||||
.name = try alloc.dupe(u8, val.name),
|
.name = try alloc.dupe(u8, entries[idx].name),
|
||||||
};
|
};
|
||||||
}
|
|
||||||
break :blk val;
|
|
||||||
},
|
|
||||||
.lt => entries = entries[0..idx],
|
|
||||||
.gt => entries = entries[idx..],
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (entries[0])
|
|
||||||
return error.NotFound;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if (entry.type != .dir)
|
if (entry.type != .dir)
|
||||||
@@ -140,17 +143,16 @@ pub fn open(self: File, alloc: std.mem.Allocator, filepath: []const u8) !File {
|
|||||||
self.super,
|
self.super,
|
||||||
),
|
),
|
||||||
.name = "",
|
.name = "",
|
||||||
};
|
}; // We don't care about deiniting this file since dir inodes don't need to be deinited and we don't have an allocd name.
|
||||||
|
|
||||||
return transient_file.open(alloc, filepath[first_element.len..]);
|
return transient_file.open(alloc, path[first_element.len + 1 ..]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extract the given File to the location.
|
/// Extract the given File to the location.
|
||||||
pub fn extract(self: File, alloc: std.mem.Allocator, io: Io, ext_loc: []const u8, options: Options) !void {
|
pub fn extract(self: File, alloc: std.mem.Allocator, io: Io, ext_loc: []const u8, options: Options) !void {
|
||||||
_ = self;
|
// TODO: do some basic processing to check if ext_loc is a folder & if self is regular file and adjust accordingly.
|
||||||
_ = alloc;
|
|
||||||
_ = io;
|
if (options.single_threaded)
|
||||||
_ = ext_loc;
|
return Decompress.single(alloc, io, self.map.memory, self.super, self.inode, ext_loc, options);
|
||||||
_ = options;
|
return Decompress.multi(alloc, io, self.map.memory, self.super, self.inode, ext_loc, options);
|
||||||
return error.TODO;
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user