ddn.archive.tar

ddn.archive.tar

TAR archive reader and writer implementing ddn.api.archive.

Supports reading and writing POSIX TAR archives in ustar, pax, and GNU formats. Implements the streaming ArchiveReader and ArchiveWriter interfaces.

Provider name convention: vendor "ddn", toString() returns "ddn-tar".

Module Initializers 1

shared static this()

Types 3

private structTarHeader

In-memory representation of a 512-byte TAR header block.

Fields
char[NAME_SIZE] name
char[8] mode
char[8] uid
char[8] gid
char[12] size
char[12] mtime
char[8] chksum
char typeflag
char[100] linkname
char[6] magic
char[2] ver
char[32] uname
char[32] gname
char[8] devmajor
char[8] devminor
char[PREFIX_SIZE] prefix
char[12] padding
HEADER_SIZE
Methods
void zero() pure nothrowZero-initialize the header.
void computeChecksum() @trusted nothrowCompute and set the header checksum.
bool verifyChecksum() const @trusted nothrowVerify the stored checksum.

TAR archive reader implementing ArchiveReader.

Reads from an in-memory byte slice. Supports ustar, GNU, and basic V7 formats.

Fields
private const(ubyte)[] _data
private ReadOptions _opts
private size_t _offset
private bool _closed
private EntryInfo _currentEntry
private size_t _entryCount
private ArchiveProgressCallback _progressCallback
Methods
ArchiveFormat format() @property const
size_t entryCount() @property const
string comment() @property const
bool nextEntry(out EntryInfo info)
bool contains(string path)
EntryInfo getEntry(string path)
void readContent(ref const EntryInfo entry, ContentSink sink)
void extractTo(ref const EntryInfo entry, string destPath)
void extractAll(string destDir)
void close()
bool isClosed() @property const
private bool isBlockAvailable(size_t size) const pure nothrow
private bool isZeroBlock(size_t offset) const pure nothrow
private EntryInfo parseHeader(size_t offset)
private size_t findEntryDataOffset(ref const EntryInfo entry)
Constructors
this(const(ubyte)[] data, ReadOptions opts)Create a TAR reader from archive data.

TAR archive writer implementing ArchiveWriter.

Produces a ustar-format TAR archive stream via a ContentSink.

Fields
private ContentSink _sink
private WriteOptions _opts
private bool _finished
private bool _closed
private ulong _bytesWritten
private size_t _entriesWritten
private ArchiveProgressCallback _progressCallback
Methods
ArchiveFormat format() @property const
void addDirectory(string path, FilePermissions perms = FilePermissions.fromOctal(octal!"755"))
void addFile(string path, const(ubyte)[] content, EntryWriteOptions opts = EntryWriteOptions.init)
void addFile(string path, scope const(ubyte)[] delegate() source, ulong size = 0, EntryWriteOptions opts = EntryWriteOptions.init)
void addFileFrom(string archivePath, string filesystemPath, EntryWriteOptions opts = EntryWriteOptions.init)
void addSymlink(string path, string target)
void addHardlink(string path, string target)
void addEntry(ref const EntryInfo info, scope const(ubyte)[] delegate() source)
void setComment(string comment)
void removeEntry(string path)
void updateEntry(string path, const(ubyte)[] content, EntryWriteOptions opts = EntryWriteOptions.init)
void finish()
void close()
bool isFinished() @property const
bool isClosed() @property const
ulong bytesWritten() @property const
size_t entriesWritten() @property const
private void writeEntry(string path, char typeFlag, ulong size, const(ubyte)[] content, FilePermissions perms)
private void writeLinkEntry(string path, char typeFlag, string target)
private void setUstarMagic(TarHeader * hdr) nothrow
private void emitBlock(const(ubyte) * data, size_t length)
Constructors
this(ContentSink sink, WriteOptions opts)Create a TAR writer.

Functions 7

private fnulong parseOctal(const(ubyte) * field, size_t length) @trusted nothrowParse an octal string from a TAR header field.
private fnvoid writeOctal(ubyte * field, size_t length, ulong value) @trusted nothrowWrite an octal value into a TAR header field.
private fnvoid writeString(ubyte * field, size_t length, const(char)[] str) @trusted nothrowWrite a string into a TAR header field, null-padded.
private fnstring readString(const(ubyte) * field, size_t length) pureRead a null-terminated string from a TAR header field.
fnArchiveReader makeTarReader(const(ubyte)[] data, ReadOptions opts)Factory function that constructs a TarReader.
fnArchiveWriter makeTarWriter(ContentSink sink, WriteOptions opts)Factory function that constructs a TarWriter.
fnArchiveFormat detectTarFormat(const(ubyte)[] header)Detect TAR format from header bytes.

Variables 10

private enumvarBLOCK_SIZE = 512
private enumvarNAME_SIZE = 100
private enumvarPREFIX_SIZE = 155
private enumvarREGTYPE = '0'
private enumvarAREGTYPE = '\0'
private enumvarDIRTYPE = '5'
private enumvarSYMTYPE = '2'
private enumvarLINKTYPE = '1'
private enumvarUSTAR_MAGIC = "ustar\0"
private enumvarGNU_MAGIC = "ustar "