47 static const byte kEndRecord[4] = { 0x50, 0x4B, 0x05, 0x06 };
49 const size_t endPos =
searchBackwards(zip, kEndRecord,
sizeof(kEndRecord), 0xFFFF);
51 throw Exception(
"End of central directory record not found");
63 if ((curDisk != 0) || (curDisk != centralDirDisk) || (curDiskDirs != totalDirs))
64 throw Exception(
"Unsupported multi-disk ZIP file");
69 zip.
seek(centralDirPos);
72 if (tag != 0x02014B50)
73 throw Exception(
"Unknown ZIP record %08X", tag);
76 while (tag == 0x02014B50) {
90 throw Exception(
"Unsupported multi-disk ZIP file");
98 zip.
skip(extraLength);
99 zip.
skip(commentLength);
102 if ((tag != 0x02014B50) && (tag != 0x06054B50))
103 throw Exception(
"Unknown ZIP record %08X", tag);
111 if (*(--file.
name.
end()) !=
'/') {
138 if (tag != 0x04034B50)
139 throw Exception(
"Unknown ZIP record %08X", tag);
153 zip.
skip(nameLength);
154 zip.
skip(extraLength);
170 if (tryNoCopy && (compMethod == 0))
186 throw Exception(
"Unhandled Zip compression %d", method);
UString name
The file's name.
uint16 readUint16LE()
Read an unsigned 16-bit word stored in little endian (LSB first) order from the stream and return it...
Internal file information.
uint32 readUint32LE()
Read an unsigned 32-bit word stored in little endian (LSB first) order from the stream and return it...
virtual size_t seek(ptrdiff_t offset, Origin whence=kOriginBegin)=0
Sets the stream position indicator for the stream.
MemoryReadStream * readStream(size_t dataSize)
Read the specified amount of data into a new[]'ed buffer which then is wrapped into a MemoryReadStrea...
Implementing the reading stream interfaces for plain memory blocks.
ScopedPtr< SeekableReadStream > _zip
byte * decompressDeflate(const byte *data, size_t inputSize, size_t outputSize, int windowBits)
Decompress (inflate) using zlib's DEFLATE algorithm.
Utility templates and functions for working with strings and streams.
SeekableReadStream * getFile(uint32 index, bool tryNoCopy=false) const
Return a stream of the file's contents.
Basic exceptions to throw.
static SeekableReadStream * decompressFile(SeekableReadStream &zip, uint32 method, uint32 compSize, uint32 realSize)
size_t searchBackwards(SeekableReadStream &haystack, const byte *needle, size_t needleSize, size_t maxReadBack)
Search the stream, backwards, for the last occurrence of a set of bytes.
const FileList & getFiles() const
Return the list of files.
ZipFile(SeekableReadStream *zip)
static const int kWindowBitsMaxRaw
Utility templates and functions.
std::list< File > FileList
virtual size_t skip(ptrdiff_t offset)
Skip the specified number of bytes, adding that offset to the current position in the stream...
uint32 size
The file's size.
Utility functions for working with differing string encodings.
bool empty() const
Is the string empty?
size_t getFileSize(uint32 index) const
Return the size of a file.
void load(SeekableReadStream &zip)
Plain, unextended ASCII (7bit clean).
UString toLower() const
Return a lowercased copy of the string.
FileList _files
External list of file names and types.
IFileList _iFiles
Internal list of file offsets and sizes.
const IFile & getIFile(uint32 index) const
UString readStringFixed(SeekableReadStream &stream, Encoding encoding, size_t length)
Read length bytes as a string with the given encoding out of a stream.
uint32 offset
The offset of the file within the ZIP.
void getFileProperties(SeekableReadStream &zip, const IFile &file, uint16 &compMethod, uint32 &compSize, uint32 &realSize) const
SeekableSubReadStream provides access to a SeekableReadStream restricted to the range [begin...
Compress (deflate) and decompress (inflate) using zlib's DEFLATE algorithm.
Interface for a seekable & readable data stream.
uint32 index
The file's local index within the ZIP.