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".
Copyright
BSD-3-Clause
var AREGTYPE BLOCK_SIZE DIRTYPE GNU_MAGIC LINKTYPE NAME_SIZE PREFIX_SIZE REGTYPE SYMTYPE USTAR_MAGIC
struct TarHeader
Module Initializers 1
shared static this
()Types 3
In-memory representation of a 512-byte TAR header block.
Fields
char[NAME_SIZE] namechar[8] modechar[8] uidchar[8] gidchar[12] sizechar[12] mtimechar[8] chksumchar typeflagchar[100] linknamechar[6] magicchar[2] verchar[32] unamechar[32] gnamechar[8] devmajorchar[8] devminorchar[PREFIX_SIZE] prefixchar[12] padding HEADER_SIZEMethods
classTarReader : ArchiveReader
TAR archive reader implementing ArchiveReader.
Reads from an in-memory byte slice. Supports ustar, GNU, and basic V7 formats.
Fields
private const(ubyte)[] _dataprivate ReadOptions _optsprivate size_t _offsetprivate bool _closedprivate EntryInfo _currentEntryprivate size_t _entryCountprivate ArchiveProgressCallback _progressCallbackMethods
void setProgressCallback(ArchiveProgressCallback callback)bool contains(string path)void readContent(ref const EntryInfo entry, ContentSink sink)void extractAll(string destDir)void close()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.classTarWriter : ArchiveWriter
TAR archive writer implementing ArchiveWriter.
Produces a ustar-format TAR archive stream via a ContentSink.
Fields
private ContentSink _sinkprivate WriteOptions _optsprivate bool _finishedprivate bool _closedprivate ulong _bytesWrittenprivate size_t _entriesWrittenprivate ArchiveProgressCallback _progressCallbackMethods
void setOutputSink(ContentSink sink)void setProgressCallback(ArchiveProgressCallback callback)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 setComment(string comment)void removeEntry(string path)void updateEntry(string path, const(ubyte)[] content,
EntryWriteOptions opts = EntryWriteOptions.init)void finish()void close()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 emitBlock(const(ubyte) * data, size_t length)Constructors
this(ContentSink sink, WriteOptions opts)Create a TAR writer.Functions 7
private fn
ulong parseOctal(const(ubyte) * field, size_t length) @trusted nothrowParse an octal string from a TAR header field.private fn
void writeOctal(ubyte * field, size_t length, ulong value) @trusted nothrowWrite an octal value into a TAR header field.private fn
void writeString(ubyte * field, size_t length, const(char)[] str) @trusted nothrowWrite a string into a TAR header field, null-padded.private fn
string readString(const(ubyte) * field, size_t length) pureRead a null-terminated string from a TAR header field.fn
ArchiveReader makeTarReader(const(ubyte)[] data, ReadOptions opts)Factory function that constructs a TarReader.fn
ArchiveWriter makeTarWriter(ContentSink sink, WriteOptions opts)Factory function that constructs a TarWriter.Variables 10
private enumvar
BLOCK_SIZE = 512private enumvar
NAME_SIZE = 100private enumvar
PREFIX_SIZE = 155private enumvar
REGTYPE = '0'private enumvar
AREGTYPE = '\0'private enumvar
DIRTYPE = '5'private enumvar
SYMTYPE = '2'private enumvar
LINKTYPE = '1'private enumvar
USTAR_MAGIC = "ustar\0"private enumvar
GNU_MAGIC = "ustar "