ddn.archive.zip
ddn.archive.zip
ZIP archive reader and writer implementing ddn.api.archive.
Copyright
Module Initializers 1
()Types 6
Delegate type for streaming byte source.
Called by ZipStreamReader to request more data from the underlying non-seekable source. The delegate should fill the provided buffer with available bytes.
Parameters
buffer | The buffer to fill with data. |
Returns
string pathulong offsetulong compressedSizeulong uncompressedSizeushort compressionMethoduint crcValushort lastModTimeushort lastModDateushort gpFlagsFilePermissions permissionsstring commentbool isUtf8private const(ubyte)[] _dataprivate ReadOptions _optsprivate bool _closedprivate CentralDirEntry[] _entriesprivate size_t _iterIndexprivate bool _iteratingprivate ArchiveProgressCallback _progressCallbackvoid setProgressCallback(ArchiveProgressCallback callback)bool contains(string path)void readContent(ref const EntryInfo entry, ContentSink sink)void extractAll(string destDir)void close()void parseCentralDirectory()void parseZip64ExtraField(ref CentralDirEntry entry,
const(ubyte) * extra, ushort extraLen)Parse the ZIP64 Extra Field from a central directory entry.Zip64Eocd parseZip64Eocd(long eocdOffset) constParse the ZIP64 End of Central Directory record.this(const(ubyte)[] data, ReadOptions opts)Zip64EocdTrue streaming ZIP reader that reads entries incrementally from a non-seekable source.
Unlike ZipReader which loads the entire archive and parses the central directory, ZipStreamReader reads local file headers sequentially, allowing processing of archives from pipes, sockets, or other non-seekable sources without buffering the entire archive in memory.
Limitations compared to ZipReader:
- No random access (
getEntry()is not supported) entryCount()returns 0 (unknown until fully read)contains()requires sequential scan- Cannot seek backwards to re-read entries
The reader handles both regular ZIP entries and entries with data descriptors (general purpose bit flag 3), as well as ZIP64 extended information.
private ByteSource _sourceprivate ReadOptions _optsprivate bool _closedprivate bool _eofprivate ArchiveProgressCallback _progressCallbackprivate size_t _entriesProcessedprivate ubyte[] _bufferprivate size_t _bufferPosprivate size_t _bufferLenprivate 262144 BUFFER_SIZEprivate bool _hasCurrentEntryprivate StreamEntryState _currentEntryArchiveCapabilities capabilities() @property constReturns the provider capabilities for streaming mode.void setProgressCallback(ArchiveProgressCallback callback)Set progress callback for operation monitoring.bool contains(string path)Check if archive contains an entry at path.void readContent(ref const EntryInfo entry, ContentSink sink)Read entry content, calling sink with chunks of decompressed data.void extractAll(string destDir)Extract all entries to a directory.void close()Close the reader and release resources.void parseLocalZip64Extra(const(ubyte)[] extra)Parse ZIP64 extended information from local file header extra field.void readAndDecompressContent(ContentSink sink)Read and decompress content of current entry, sending to sink.void readContentWithDataDescriptor(ContentSink sink)Read content when size is in data descriptor (streaming with unknown size).this(ByteSource source, ReadOptions opts)Construct a streaming ZIP reader.StreamEntryStatestring pathulong localHeaderOffsetulong compressedSizeulong uncompressedSizeushort compressionMethoduint crcValFilePermissions permissionsstring commentushort lastModTimeushort lastModDateprivate ContentSink _sinkprivate WriteOptions _optsprivate bool _finishedprivate bool _closedprivate ulong _bytesWrittenprivate size_t _entriesWrittenprivate ArchiveProgressCallback _progressCallbackprivate LocalDirEntry[] _localEntriesvoid 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()ushort getCompressionMethod()bool needsZip64(ulong uncompressedSize, ulong compressedSize) constCheck if a local file entry needs ZIP64 extended fields.void writeLocalFile(string path, const(ubyte)[] content,
FilePermissions perms, bool isDirectory, ushort modTime = 0,
ushort modDate = 0x0021)void writeCentralDirectoryEntry(ref const LocalDirEntry entry)void writeZip64EndOfCentralDirectory(ulong cdOffset, ulong cdSize)Write the ZIP64 End of Central Directory record and its locator.void writeEndOfCentralDirectory(ulong cdOffset, ulong cdSize,
bool zip64)Write the regular End of Central Directory record.this(ContentSink sink, WriteOptions opts)Functions 16
ulong readU64(const(ubyte) * p) @trusted pure nothrowRead a little-endian 64-bit unsigned integer.void writeU64(ubyte * p, ulong v) @trusted pure nothrowWrite a little-endian 64-bit unsigned integer.uint computeCrc32(const(ubyte)[] data) nothrowCompute CRC-32 checksum using ddn.compressor.zlib.ubyte[] deflateRaw(const(ubyte)[] data)Compress data using raw DEFLATE (RFC 1951) via ddn-compressor-base zlib.ubyte[] inflateRaw(const(ubyte)[] data)Decompress raw DEFLATE (RFC 1951) data via ddn-compressor-base zlib.EntryInfo makeEntryInfo(string path, EntryType etype, ulong usize,
ulong csize, uint crcv, FilePermissions perms, ushort method,
ushort modTime = 0, ushort modDate = 0)void unixTimeToDosDateTime(long unixSeconds, out ushort dosTime, out ushort dosDate)Convert a Unix timestamp to DOS date and time values for ZIP headers.void patchCdEntryToZip64(ref ubyte[] data)Patch a normal ZIP archive to simulate ZIP64 structures for testing.ArchiveReader makeZipReader(const(ubyte)[] data, ReadOptions opts)Create a ZipReader for reading from an in-memory buffer.ArchiveReader makeZipStreamReader(ByteSource source, ReadOptions opts)Create a ZipStreamReader for reading from a streaming byte source.ArchiveWriter makeZipWriter(ContentSink sink, WriteOptions opts)Create a ZipWriter for writing to an output sink.ArchiveFormat detectZipFormat(const(ubyte)[] header)Variables 16
LOCAL_FILE_HEADER_SIG = 0x04034B50CENTRAL_DIR_HEADER_SIG = 0x02014B50END_CENTRAL_DIR_SIG = 0x06054B50ZIP64_END_CENTRAL_DIR_SIG = 0x06064B50ZIP64_END_CENTRAL_DIR_LOCATOR_SIG = 0x07064B50DATA_DESCRIPTOR_SIG = 0x08074B50ZIP64_EXTRA_FIELD_ID = 0x0001COMPRESS_STORED = 0COMPRESS_DEFLATED = 8VERSION_NEEDED = 20VERSION_NEEDED_ZIP64 = 45VERSION_MADE_BY = 20VERSION_MADE_BY_ZIP64 = 45GP_FLAG_UTF8 = 1 << 11GP_FLAG_DATA_DESCRIPTOR = 1 << 3ZIP32_MAX = 0xFFFFFFFF