| ... | @@ -1,4 +1,3 @@ | ... | @@ -1,4 +1,3 @@ |
| 1 | <<<<<<< HEAD | | |
| 2 | //! Tar archive is single ordinary file which can contain many files (or | 1 | //! Tar archive is single ordinary file which can contain many files (or |
| 3 | //! directories, symlinks, ...). It's build by series of blocks each size of 512 | 2 | //! directories, symlinks, ...). It's build by series of blocks each size of 512 |
| 4 | //! bytes. First block of each entry is header which defines type, name, size | 3 | //! bytes. First block of each entry is header which defines type, name, size |
| ... | @@ -16,7 +15,7 @@ | ... | @@ -16,7 +15,7 @@ |
| 16 | //! GNU tar reference: https://www.gnu.org/software/tar/manual/html_node/Standard.html | 15 | //! GNU tar reference: https://www.gnu.org/software/tar/manual/html_node/Standard.html |
| 17 | //! pax reference: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/pax.html#tag_20_92_13 | 16 | //! pax reference: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/pax.html#tag_20_92_13 |
| 18 | | 17 | |
| 19 | const std = @import("std.zig"); | 18 | const std = @import("std"); |
| 20 | const assert = std.debug.assert; | 19 | const assert = std.debug.assert; |
| 21 | | 20 | |
| 22 | pub const output = @import("tar/output.zig"); | 21 | pub const output = @import("tar/output.zig"); |
| ... | @@ -250,6 +249,33 @@ pub const IteratorOptions = struct { | ... | @@ -250,6 +249,33 @@ pub const IteratorOptions = struct { |
| 250 | | 249 | |
| 251 | /// Iterates over files in tar archive. | 250 | /// Iterates over files in tar archive. |
| 252 | /// `next` returns each file in `reader` tar archive. | 251 | /// `next` returns each file in `reader` tar archive. |
| | 252 | /// |
| | 253 | /// Init iterator with tar archive reader and provided buffers: |
| | 254 | /// |
| | 255 | /// var file_name_buffer: [std.fs.MAX_PATH_BYTES]u8 = undefined; |
| | 256 | /// var link_name_buffer: [std.fs.MAX_PATH_BYTES]u8 = undefined; |
| | 257 | /// |
| | 258 | /// var iter = std.tar.iterator(archive.reader(), .{ |
| | 259 | /// .file_name_buffer = &file_name_buffer, |
| | 260 | /// .link_name_buffer = &link_name_buffer, |
| | 261 | /// }); |
| | 262 | /// |
| | 263 | /// Iterate on each tar archive file: |
| | 264 | /// |
| | 265 | /// while (try iter.next()) |file| { |
| | 266 | /// switch (file.kind) { |
| | 267 | /// .directory => { |
| | 268 | /// // try dir.makePath(file.name); |
| | 269 | /// }, |
| | 270 | /// .file => { |
| | 271 | /// // try file.writeAll(writer); |
| | 272 | /// }, |
| | 273 | /// .sym_link => { |
| | 274 | /// // try dir.symLink(file.link_name, file.name, .{}); |
| | 275 | /// }, |
| | 276 | /// } |
| | 277 | /// } |
| | 278 | /// |
| 253 | pub fn iterator(reader: anytype, options: IteratorOptions) Iterator(@TypeOf(reader)) { | 279 | pub fn iterator(reader: anytype, options: IteratorOptions) Iterator(@TypeOf(reader)) { |
| 254 | return .{ | 280 | return .{ |
| 255 | .reader = reader, | 281 | .reader = reader, |