openMSX
ZipFileAdapter.cc
Go to the documentation of this file.
1#include "ZipFileAdapter.hh"
2#include "ZlibInflate.hh"
3#include "FileException.hh"
4
5namespace openmsx {
6
7ZipFileAdapter::ZipFileAdapter(std::unique_ptr<FileBase> file_)
8 : CompressedFileAdapter(std::move(file_))
9{
10}
11
12void ZipFileAdapter::decompress(FileBase& f, Decompressed& d)
13{
14 ZlibInflate zlib(f.mmap());
15
16 if (zlib.get32LE() != 0x04034B50) {
17 throw FileException("Invalid ZIP file");
18 }
19
20 // skip "version needed to extract" and "general purpose bit flag"
21 zlib.skip(2 + 2);
22
23 // compression method
24 if (zlib.get16LE() != 0x0008) {
25 throw FileException("Unsupported zip compression method");
26 }
27
28 // skip "last mod file time", "last mod file data",
29 // "crc32", "compressed size"
30 zlib.skip(2 + 2 + 4 + 4);
31
32 unsigned origSize = zlib.get32LE(); // uncompressed size
33 unsigned filenameLen = zlib.get16LE(); // filename length
34 unsigned extraFieldLen = zlib.get16LE(); // extra field length
35 d.originalName = zlib.getString(filenameLen); // original filename
36 zlib.skip(extraFieldLen); // skip "extra field"
37
38 d.buf = zlib.inflate(origSize);
39}
40
41} // namespace openmsx
virtual std::span< const uint8_t > mmap()
Definition FileBase.cc:9
ZipFileAdapter(std::unique_ptr< FileBase > file)
This file implemented 3 utility functions:
Definition Autofire.cc:11
STL namespace.