forked from organicmaps/organicmaps
Added ZipReader::UncompressedSize(). Compressed size is returned by base method Reader::Size()
This commit is contained in:
parent
31061cd31a
commit
2499a05544
3 changed files with 38 additions and 9 deletions
|
@ -181,3 +181,30 @@ UNIT_TEST(ZipExtract)
|
|||
|
||||
FileWriter::DeleteFileX(ZIPFILE);
|
||||
}
|
||||
|
||||
UNIT_TEST(ZipFileSizes)
|
||||
{
|
||||
string const ZIPFILE = "test.zip";
|
||||
{
|
||||
FileWriter f(ZIPFILE);
|
||||
f.Write(zipBytes3, ARRAY_SIZE(zipBytes3));
|
||||
}
|
||||
TEST(ZipFileReader::IsZip(ZIPFILE), ("Not a zip file"));
|
||||
|
||||
vector<string> files = ZipFileReader::FilesList(ZIPFILE);
|
||||
TEST_EQUAL(files.size(), 2, ());
|
||||
|
||||
{
|
||||
ZipFileReader file(ZIPFILE, files[0]);
|
||||
TEST_EQUAL(file.Size(), 6, ());
|
||||
TEST_EQUAL(file.UncompressedSize(), 11, ());
|
||||
}
|
||||
|
||||
{
|
||||
ZipFileReader file(ZIPFILE, files[1]);
|
||||
TEST_EQUAL(file.Size(), 8, ());
|
||||
TEST_EQUAL(file.UncompressedSize(), 9, ());
|
||||
}
|
||||
|
||||
FileWriter::DeleteFileX(ZIPFILE);
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
#include "../3party/zlib/contrib/minizip/unzip.h"
|
||||
|
||||
ZipFileReader::ZipFileReader(string const & container, string const & file)
|
||||
: BaseZipFileReaderType(container)
|
||||
: BaseZipFileReaderType(container), m_uncompressedFileSize(0)
|
||||
{
|
||||
unzFile zip = unzOpen64(container.c_str());
|
||||
if (!zip)
|
||||
|
@ -32,14 +32,10 @@ ZipFileReader::ZipFileReader(string const & container, string const & file)
|
|||
|
||||
unz_file_info64 fileInfo;
|
||||
if (UNZ_OK != unzGetCurrentFileInfo64(zip, &fileInfo, NULL, 0, NULL, 0, NULL, 0))
|
||||
MYTHROW(LocateZipException, ("Can't get uncompressed file size inside zip", file));
|
||||
MYTHROW(LocateZipException, ("Can't get compressed file size inside zip", file));
|
||||
|
||||
if (fileInfo.compressed_size != fileInfo.uncompressed_size)
|
||||
MYTHROW(InvalidZipException, ("File should be uncompressed inside zip", file));
|
||||
|
||||
LOG(LDEBUG, (file, "offset:", offset, "size:", fileInfo.uncompressed_size));
|
||||
|
||||
SetOffsetAndSize(offset, fileInfo.uncompressed_size);
|
||||
SetOffsetAndSize(offset, fileInfo.compressed_size);
|
||||
m_uncompressedFileSize = fileInfo.uncompressed_size;
|
||||
}
|
||||
|
||||
vector<string> ZipFileReader::FilesList(string const & zipContainer)
|
||||
|
|
|
@ -13,6 +13,9 @@
|
|||
|
||||
class ZipFileReader : public BaseZipFileReaderType
|
||||
{
|
||||
private:
|
||||
uint64_t m_uncompressedFileSize;
|
||||
|
||||
public:
|
||||
DECLARE_EXCEPTION(OpenZipException, OpenException);
|
||||
DECLARE_EXCEPTION(LocateZipException, OpenException);
|
||||
|
@ -20,7 +23,10 @@ public:
|
|||
|
||||
ZipFileReader(string const & container, string const & file);
|
||||
|
||||
// Can also throw Writer::OpenException and Writer::WriteException
|
||||
/// @note Size() returns compressed file size inside zip
|
||||
uint64_t UncompressedSize() const { return m_uncompressedFileSize; }
|
||||
|
||||
/// @warning Can also throw Writer::OpenException and Writer::WriteException
|
||||
static void UnzipFile(string const & zipContainer, string const & fileInZip,
|
||||
string const & outFilePath);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue