ddn.archive.cpio

ddn.archive.cpio

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

Supports the SVR4 newc (new ASCII) CPIO format, which is the most widely used variant. The newc format uses 110-byte headers with 8-character hexadecimal ASCII fields.

Module Initializers 1

shared static this()

Types 3

private structCpioEntry
Fields
string path
ulong dataOffset
ulong size
uint mode
uint mtime
uint uid
uint gid
uint devMajor
uint devMinor
uint rdevMajor
uint rdevMinor
Fields
private const(ubyte)[] _data
private ReadOptions _opts
private bool _closed
private CpioEntry[] _entries
private size_t _iterIndex
private bool _iterating
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 void parseArchive()
Constructors
this(const(ubyte)[] data, ReadOptions opts)
Fields
private ContentSink _sink
private WriteOptions _opts
private bool _finished
private bool _closed
private ulong _bytesWritten
private size_t _entriesWritten
private ArchiveProgressCallback _progressCallback
private ulong _nextIno
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 removeEntry(string path)
void updateEntry(string path, const(ubyte)[] content, EntryWriteOptions opts = EntryWriteOptions.init)
void setComment(string comment)
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 name, const(ubyte)[] data, uint mode, ulong nlink)
private void writeTrailer()
private void emit(const(ubyte)[] data)
Constructors

Functions 8

private fnulong parseCpioHexField(const(ubyte) * field) pure nothrowParse an 8-character hex ASCII field from a CPIO newc header.
private fnvoid writeCpioHexField(ubyte * field, ulong value) @trusted nothrowWrite an 8-character hex ASCII field into a CPIO newc header.
private fnsize_t align4(size_t offset) pure nothrow @nogcAlign an offset up to the next 4-byte boundary.
private fnEntryType modeToEntryType(uint mode) pure nothrow @nogcDetermine EntryType from POSIX mode bits.
private fnuint entryTypeToMode(EntryType type) pure nothrow @nogcConvert EntryType to POSIX mode bits (upper portion only).
fnArchiveReader makeCpioReader(const(ubyte)[] data, ReadOptions opts)
fnArchiveFormat detectCpioFormat(const(ubyte)[] header)

Variables 12

private enumvarCPIO_NEWC_MAGIC = "070701"
private enumvarCPIO_CRC_MAGIC = "070702"
private enumvarCPIO_TRAILER = "TRAILER!!!"
private enumvarCPIO_HEADER_SIZE = 110
private enumvarS_IFMT = octal!"170000"
private enumvarS_IFREG = octal!"100000"
private enumvarS_IFDIR = octal!"040000"
private enumvarS_IFLNK = octal!"120000"
private enumvarS_IFSOCK = octal!"140000"
private enumvarS_IFIFO = octal!"010000"
private enumvarS_IFCHR = octal!"020000"
private enumvarS_IFBLK = octal!"060000"