![]() |
NDEVR
API Documentation
|
Provides utilities for reading and extracting TAR and TAR.GZ archives. More...
Classes | |
| struct | FileReader |
| Reader implementation for uncompressed files using std::ifstream. More... | |
| struct | GzReader |
| Reader implementation for gzip-compressed files using zlib's gzFile interface. More... | |
| struct | Reader |
| Abstract base class for sequential byte stream reading. More... | |
| struct | TarHdr |
| Represents the raw 512-byte POSIX TAR header structure (USTAR format). More... | |
Static Public Member Functions | |
| static bool | all_zero (const u8 *p, size_t n) |
| Checks whether all bytes in a buffer are zero. | |
| static void | apply_mode (const fs::path &p, u64 mode) |
| Applies POSIX file permissions to the given path based on a TAR mode value. | |
| static void | apply_mtime (const fs::path &p, u64 mtime) |
| Sets the last modification time of a file to the given Unix timestamp. | |
| static int | Extract (const File &src, const File &dest) |
| Extracts all entries from a TAR or TAR.GZ archive to a destination directory. | |
| static std::string | hdr_name (const TarHdr &h) |
| Extracts the full file name from a TAR header, combining prefix and name fields. | |
| static u64 | parse_octal (const char *p, size_t n) |
| Parses an octal number from a TAR header field string. | |
| static bool | read_block (Reader &r, u8 *buf) |
| Reads a single 512-byte block from the reader. | |
| static std::string | read_pax_string (const std::string &rec) |
| Returns a PAX extended attribute record string as-is. | |
| static bool | skip_bytes (Reader &r, u64 n, std::vector< u8 > &tmp) |
| Skips over a specified number of bytes in the reader stream. | |
| static bool | starts_with (const fs::path &a, const fs::path &base) |
| Checks whether path a starts with the given base path using weakly canonical forms. | |
| static u64 | tar_checksum (const u8 *h) |
| Computes the TAR checksum for a 512-byte header block. | |
| static bool | valid_hdr (const u8 *blk) |
| Validates a 512-byte TAR header block by verifying its checksum. | |
Provides utilities for reading and extracting TAR and TAR.GZ archives.
Definition at line 18 of file TarReader.h.
|
inlinestatic |
Checks whether all bytes in a buffer are zero.
| [in] | p | Pointer to the buffer. |
| [in] | n | Number of bytes to check. |
Definition at line 138 of file TarReader.h.
Referenced by Extract().
|
inlinestatic |
Applies POSIX file permissions to the given path based on a TAR mode value.
| [in] | p | The filesystem path to apply permissions to. |
| [in] | mode | The POSIX mode bits to apply. |
Definition at line 240 of file TarReader.h.
Referenced by Extract().
|
inlinestatic |
Sets the last modification time of a file to the given Unix timestamp.
| [in] | p | The filesystem path to update. |
| [in] | mtime | The modification time as seconds since Unix epoch. |
Definition at line 260 of file TarReader.h.
Referenced by Extract().
Extracts all entries from a TAR or TAR.GZ archive to a destination directory.
Supports regular files, directories, symbolic links, hard links, PAX extended headers, and GNU long name/link extensions. Automatically detects gzip compression by inspecting the file signature.
| [in] | src | The source TAR or TAR.GZ archive file. |
| [in] | dest | The destination directory to extract into. |
Definition at line 312 of file TarReader.h.
References all_zero(), apply_mode(), apply_mtime(), String::c_str(), TAR::FileReader::f, TAR::GzReader::g, hdr_name(), TAR::TarHdr::linkname, TAR::TarHdr::magic, TAR::TarHdr::mode, TAR::TarHdr::mtime, name, parse_octal(), read_block(), TAR::TarHdr::size, skip_bytes(), starts_with(), type, TAR::TarHdr::typeflag, and valid_hdr().
|
inlinestatic |
Extracts the full file name from a TAR header, combining prefix and name fields.
| [in] | h | The TAR header to extract the name from. |
Definition at line 202 of file TarReader.h.
References TAR::TarHdr::name, and TAR::TarHdr::prefix.
Referenced by Extract().
|
inlinestatic |
Parses an octal number from a TAR header field string.
| [in] | p | Pointer to the octal string. |
| [in] | n | Maximum number of characters to parse. |
Definition at line 149 of file TarReader.h.
Referenced by Extract(), and valid_hdr().
|
inlinestatic |
Reads a single 512-byte block from the reader.
| [in] | r | The reader to read from. |
| [in] | buf | Buffer to store the 512-byte block. |
Definition at line 273 of file TarReader.h.
References TAR::Reader::read_exact().
Referenced by Extract().
|
inlinestatic |
Returns a PAX extended attribute record string as-is.
| [in] | rec | The PAX record string. |
Definition at line 231 of file TarReader.h.
|
inlinestatic |
Skips over a specified number of bytes in the reader stream.
| [in] | r | The reader to skip bytes from. |
| [in] | n | Number of bytes to skip. |
| [in] | tmp | Temporary buffer used for reading and discarding data. |
Definition at line 284 of file TarReader.h.
References TAR::Reader::read_exact().
Referenced by Extract().
|
inlinestatic |
Checks whether path a starts with the given base path using weakly canonical forms.
| [in] | a | The path to check. |
| [in] | base | The base path to compare against. |
Definition at line 122 of file TarReader.h.
Referenced by Extract().
|
inlinestatic |
Computes the TAR checksum for a 512-byte header block.
| [in] | h | Pointer to the 512-byte header block. |
Definition at line 165 of file TarReader.h.
Referenced by valid_hdr().
|
inlinestatic |
Validates a 512-byte TAR header block by verifying its checksum.
| [in] | blk | Pointer to the 512-byte header block. |
Definition at line 220 of file TarReader.h.
References TAR::TarHdr::chksum, parse_octal(), and tar_checksum().
Referenced by Extract().