structstd.zip.Diagnostics[src]

Fields

allocator: std.mem.Allocator
root_dir: []const u8 = ""

The common root directory for all extracted files if there is one.

saw_first_file: bool = false

Functions

Functiondeinit[src]

pub fn deinit(self: *Diagnostics) void

Parameters

Source Code

Source code
pub fn deinit(self: *Diagnostics) void {
    self.allocator.free(self.root_dir);
    self.* = undefined;
}

FunctionnextFilename[src]

pub fn nextFilename(self: *Diagnostics, name: []const u8) error{OutOfMemory}!void

Parameters

name: []const u8

Source Code

Source code
pub fn nextFilename(self: *Diagnostics, name: []const u8) error{OutOfMemory}!void {
    if (!self.saw_first_file) {
        self.saw_first_file = true;
        std.debug.assert(self.root_dir.len == 0);
        const root_len = std.mem.indexOfScalar(u8, name, '/') orelse return;
        std.debug.assert(root_len > 0);
        self.root_dir = try self.allocator.dupe(u8, name[0..root_len]);
    } else if (self.root_dir.len > 0) {
        if (!filenameInRoot(name, self.root_dir)) {
            self.allocator.free(self.root_dir);
            self.root_dir = "";
        }
    }
}

Source Code

Source code
pub const Diagnostics = struct {
    allocator: std.mem.Allocator,

    /// The common root directory for all extracted files if there is one.
    root_dir: []const u8 = "",

    saw_first_file: bool = false,

    pub fn deinit(self: *Diagnostics) void {
        self.allocator.free(self.root_dir);
        self.* = undefined;
    }

    // This function assumes name is a filename from a zip file which has already been verified to
    // not start with a slash, backslashes have been normalized to forward slashes, and directories
    // always end in a slash.
    pub fn nextFilename(self: *Diagnostics, name: []const u8) error{OutOfMemory}!void {
        if (!self.saw_first_file) {
            self.saw_first_file = true;
            std.debug.assert(self.root_dir.len == 0);
            const root_len = std.mem.indexOfScalar(u8, name, '/') orelse return;
            std.debug.assert(root_len > 0);
            self.root_dir = try self.allocator.dupe(u8, name[0..root_len]);
        } else if (self.root_dir.len > 0) {
            if (!filenameInRoot(name, self.root_dir)) {
                self.allocator.free(self.root_dir);
                self.root_dir = "";
            }
        }
    }
}