diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main.zig | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/src/main.zig b/src/main.zig index a1fb23b..ab3e937 100644 --- a/src/main.zig +++ b/src/main.zig @@ -3,7 +3,7 @@ const std = @import("std"); // ZIP file implementation // See spec.txt. -const CompressionMethod = enum(u16) { +pub const CompressionMethod = enum(u16) { store = 0, shrink = 1, reduce_1 = 2, @@ -190,7 +190,7 @@ fn pump_returning(reader: anytype, writer: anytype) !struct { u64, u32 } { return res; } -const CentralDirectoryHeader = struct { +pub const CentralDirectoryHeader = struct { const SIG: u32 = @as(u32, 0x02014b50); version_made_by: u16, version_needed_to_extract: u16, @@ -212,7 +212,7 @@ const CentralDirectoryHeader = struct { extra_field: []const u8, file_comment: []const u8, - fn read(allocator: std.mem.Allocator, reader: anytype) !CentralDirectoryHeader { + pub fn read(allocator: std.mem.Allocator, reader: anytype) !CentralDirectoryHeader { return read2(allocator, reader, CentralDirectoryHeader, &[_]Dynamic{ .{ .field_name = "file_name", .length_field_name = "file_name_length" }, .{ .field_name = "extra_field", .length_field_name = "extra_field_length" }, @@ -220,7 +220,7 @@ const CentralDirectoryHeader = struct { }); } - fn write(self: *CentralDirectoryHeader, writer: anytype) !void { + pub fn write(self: *CentralDirectoryHeader, writer: anytype) !void { // TODO generics self.file_name_length = @intCast(self.file_name.len); self.extra_field_length = @intCast(self.extra_field.len); @@ -248,7 +248,7 @@ const CentralDirectoryHeader = struct { try writer.writeAll(self.file_comment); } - fn from(allocator: std.mem.Allocator, lfh: LocalFileHeader, offset: u32) !CentralDirectoryHeader { + pub fn from(allocator: std.mem.Allocator, lfh: LocalFileHeader, offset: u32) !CentralDirectoryHeader { // TODO generics return .{ .version_made_by = 0, @@ -273,14 +273,14 @@ const CentralDirectoryHeader = struct { }; } - fn deinit(self: *CentralDirectoryHeader, allocator: std.mem.Allocator) void { + pub fn deinit(self: *CentralDirectoryHeader, allocator: std.mem.Allocator) void { allocator.free(self.file_name); allocator.free(self.extra_field); allocator.free(self.file_comment); } }; -const EndOfCentralDirectoryRecord = struct { +pub const EndOfCentralDirectoryRecord = struct { const SIG: u32 = @as(u32, 0x06054b50); disk_number_this: u16, disk_number_central_dir_start: u16, @@ -291,13 +291,13 @@ const EndOfCentralDirectoryRecord = struct { comment_length: u16, comment: []const u8, - fn read(allocator: std.mem.Allocator, reader: anytype) !EndOfCentralDirectoryRecord { + pub fn read(allocator: std.mem.Allocator, reader: anytype) !EndOfCentralDirectoryRecord { return read2(allocator, reader, EndOfCentralDirectoryRecord, &[_]Dynamic{ .{ .field_name = "comment", .length_field_name = "comment_length" }, }); } - fn empty() EndOfCentralDirectoryRecord { + pub fn empty() EndOfCentralDirectoryRecord { return .{ .disk_number_this = 0, .disk_number_central_dir_start = 0, @@ -310,7 +310,7 @@ const EndOfCentralDirectoryRecord = struct { }; } - fn write(self: *EndOfCentralDirectoryRecord, writer: anytype) !void { + pub fn write(self: *EndOfCentralDirectoryRecord, writer: anytype) !void { self.comment_length = @intCast(self.comment.len); try writer.writeIntLittle(u32, SIG); try writer.writeIntLittle(u16, self.disk_number_this); @@ -323,12 +323,12 @@ const EndOfCentralDirectoryRecord = struct { try writer.writeAll(self.comment); } - fn deinit(self: *EndOfCentralDirectoryRecord, allocator: std.mem.Allocator) void { + pub fn deinit(self: *EndOfCentralDirectoryRecord, allocator: std.mem.Allocator) void { allocator.free(self.comment); } }; -const LocalFileHeader = struct { +pub const LocalFileHeader = struct { const SIG: u32 = @as(u32, 0x04034b50); version_needed_to_extract: u16, general_purpose_bit_flag: std.bit_set.IntegerBitSet(16), @@ -343,14 +343,14 @@ const LocalFileHeader = struct { file_name: []const u8, extra_field: []const u8, - fn read(allocator: std.mem.Allocator, reader: anytype) !LocalFileHeader { + pub fn read(allocator: std.mem.Allocator, reader: anytype) !LocalFileHeader { return read2(allocator, reader, LocalFileHeader, &[_]Dynamic{ .{ .field_name = "file_name", .length_field_name = "file_name_length" }, .{ .field_name = "extra_field", .length_field_name = "extra_field_length" }, }); } - fn from(allocator: std.mem.Allocator, path: []const u8) !LocalFileHeader { + pub fn from(allocator: std.mem.Allocator, path: []const u8) !LocalFileHeader { std.log.err("lfh.from {s}", .{path}); const file = try std.fs.cwd().openFile(path, .{}); defer file.close(); @@ -377,7 +377,7 @@ const LocalFileHeader = struct { }; } - fn write(self: *LocalFileHeader, writer: anytype) !void { + pub fn write(self: *LocalFileHeader, writer: anytype) !void { self.file_name_length = @intCast(self.file_name.len); self.extra_field_length = @intCast(self.extra_field.len); try writer.writeIntLittle(u32, SIG); @@ -395,16 +395,16 @@ const LocalFileHeader = struct { try writer.writeAll(self.extra_field); } - fn deinit(self: *LocalFileHeader, allocator: std.mem.Allocator) void { + pub fn deinit(self: *LocalFileHeader, allocator: std.mem.Allocator) void { allocator.free(self.file_name); allocator.free(self.extra_field); } - fn is_dir(self: *LocalFileHeader) bool { + pub fn is_dir(self: *LocalFileHeader) bool { return std.mem.endsWith(u8, self.file_name, "/"); // This is what the java stdlib does } - fn extract(self: *LocalFileHeader, allocator: std.mem.Allocator, reader: anytype, writer: anytype) !void { + pub fn extract(self: *LocalFileHeader, allocator: std.mem.Allocator, reader: anytype, writer: anytype) !void { const is_encrypted = self.general_purpose_bit_flag.isSet(0); if (is_encrypted) return error.EncryptionNotSupported; @@ -441,7 +441,7 @@ const LocalFileHeader = struct { } } - fn write_data(self: *LocalFileHeader, allocator: std.mem.Allocator, reader: anytype, writer: anytype) !void { + pub fn write_data(self: *LocalFileHeader, allocator: std.mem.Allocator, reader: anytype, writer: anytype) !void { const is_encrypted = self.general_purpose_bit_flag.isSet(0); if (is_encrypted) return error.EncryptionNotSupported; |