From 970732dc453f84bdf4e232490925ee7c48513734 Mon Sep 17 00:00:00 2001 From: Pierre Lecesne Date: Thu, 2 Feb 2017 23:13:58 +0000 Subject: [PATCH] Expose whether a file was compressed before being loaded in memory. This is useful when we want to write an APK and keep the same compression parameters as the original APK. Test: Unit tests pass. Change-Id: I3afcae1c8727e429b08c9ac7359cf0789ff4abfc --- tools/aapt2/io/File.h | 5 +++++ tools/aapt2/io/ZipArchive.cpp | 4 ++++ tools/aapt2/io/ZipArchive.h | 1 + 3 files changed, 10 insertions(+) diff --git a/tools/aapt2/io/File.h b/tools/aapt2/io/File.h index 3d5b5b11707e3..1ef9743f65cf0 100644 --- a/tools/aapt2/io/File.h +++ b/tools/aapt2/io/File.h @@ -63,6 +63,11 @@ class IFile { IFile* CreateFileSegment(size_t offset, size_t len); + /** Returns whether the file was compressed before it was stored in memory. */ + virtual bool WasCompressed() { + return false; + } + private: // Any segments created from this IFile need to be owned by this IFile, so // keep them diff --git a/tools/aapt2/io/ZipArchive.cpp b/tools/aapt2/io/ZipArchive.cpp index 62b436fe4dc7d..debc484bca925 100644 --- a/tools/aapt2/io/ZipArchive.cpp +++ b/tools/aapt2/io/ZipArchive.cpp @@ -59,6 +59,10 @@ std::unique_ptr ZipFile::OpenAsData() { const Source& ZipFile::GetSource() const { return source_; } +bool ZipFile::WasCompressed() { + return zip_entry_.method != kCompressStored; +} + ZipFileCollectionIterator::ZipFileCollectionIterator( ZipFileCollection* collection) : current_(collection->files_.begin()), end_(collection->files_.end()) {} diff --git a/tools/aapt2/io/ZipArchive.h b/tools/aapt2/io/ZipArchive.h index 634adad8af329..f47287f32e9be 100644 --- a/tools/aapt2/io/ZipArchive.h +++ b/tools/aapt2/io/ZipArchive.h @@ -40,6 +40,7 @@ class ZipFile : public IFile { std::unique_ptr OpenAsData() override; const Source& GetSource() const override; + bool WasCompressed() override; private: ZipArchiveHandle zip_handle_;