1 /* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef AAPT_FLATTEN_ARCHIVE_H 18 #define AAPT_FLATTEN_ARCHIVE_H 19 20 #include "Diagnostics.h" 21 #include "util/BigBuffer.h" 22 #include "util/Files.h" 23 #include "util/StringPiece.h" 24 25 #include <google/protobuf/io/zero_copy_stream_impl_lite.h> 26 #include <fstream> 27 #include <memory> 28 #include <string> 29 #include <vector> 30 31 namespace aapt { 32 33 struct ArchiveEntry { 34 enum : uint32_t { 35 kCompress = 0x01, 36 kAlign = 0x02, 37 }; 38 39 std::string path; 40 uint32_t flags; 41 size_t uncompressedSize; 42 }; 43 44 struct IArchiveWriter : public google::protobuf::io::CopyingOutputStream { 45 virtual ~IArchiveWriter() = default; 46 47 virtual bool startEntry(const StringPiece& path, uint32_t flags) = 0; 48 virtual bool writeEntry(const BigBuffer& buffer) = 0; 49 virtual bool writeEntry(const void* data, size_t len) = 0; 50 virtual bool finishEntry() = 0; 51 52 // CopyingOutputStream implementations. WriteIArchiveWriter53 bool Write(const void* buffer, int size) override { 54 return writeEntry(buffer, size); 55 } 56 }; 57 58 std::unique_ptr<IArchiveWriter> createDirectoryArchiveWriter(IDiagnostics* diag, 59 const StringPiece& path); 60 61 std::unique_ptr<IArchiveWriter> createZipFileArchiveWriter(IDiagnostics* diag, 62 const StringPiece& path); 63 64 } // namespace aapt 65 66 #endif /* AAPT_FLATTEN_ARCHIVE_H */ 67