blob: f0681bdd11679429f4b7c6b8942feae88b1cfc4f [file] [log] [blame]
Adam Lesinski1ab598f2015-08-14 14:26:04 -07001/*
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
Adam Lesinski1ab598f2015-08-14 14:26:04 -070020#include <fstream>
21#include <memory>
22#include <string>
23#include <vector>
24
Adam Lesinskid5083f62017-01-16 15:07:21 -080025#include "androidfw/StringPiece.h"
Adam Lesinskice5e56e2016-10-21 17:56:45 -070026#include "google/protobuf/io/zero_copy_stream_impl_lite.h"
27
28#include "Diagnostics.h"
29#include "util/BigBuffer.h"
30#include "util/Files.h"
Adam Lesinskice5e56e2016-10-21 17:56:45 -070031
Adam Lesinski1ab598f2015-08-14 14:26:04 -070032namespace aapt {
33
34struct ArchiveEntry {
Adam Lesinskicacb28f2016-10-19 12:18:14 -070035 enum : uint32_t {
36 kCompress = 0x01,
37 kAlign = 0x02,
38 };
Adam Lesinski1ab598f2015-08-14 14:26:04 -070039
Adam Lesinskicacb28f2016-10-19 12:18:14 -070040 std::string path;
41 uint32_t flags;
Adam Lesinskice5e56e2016-10-21 17:56:45 -070042 size_t uncompressed_size;
Adam Lesinski1ab598f2015-08-14 14:26:04 -070043};
44
Adam Lesinski5eeaadd2016-08-25 12:26:56 -070045class IArchiveWriter : public google::protobuf::io::CopyingOutputStream {
Adam Lesinskicacb28f2016-10-19 12:18:14 -070046 public:
47 virtual ~IArchiveWriter() = default;
Adam Lesinski1ab598f2015-08-14 14:26:04 -070048
Adam Lesinskid5083f62017-01-16 15:07:21 -080049 virtual bool StartEntry(const android::StringPiece& path, uint32_t flags) = 0;
Adam Lesinskice5e56e2016-10-21 17:56:45 -070050 virtual bool WriteEntry(const BigBuffer& buffer) = 0;
51 virtual bool WriteEntry(const void* data, size_t len) = 0;
52 virtual bool FinishEntry() = 0;
Adam Lesinski59e04c62016-02-04 15:59:23 -080053
Adam Lesinskicacb28f2016-10-19 12:18:14 -070054 // CopyingOutputStream implementations.
55 bool Write(const void* buffer, int size) override {
Adam Lesinskice5e56e2016-10-21 17:56:45 -070056 return WriteEntry(buffer, size);
Adam Lesinskicacb28f2016-10-19 12:18:14 -070057 }
Adam Lesinski1ab598f2015-08-14 14:26:04 -070058};
59
Adam Lesinskid5083f62017-01-16 15:07:21 -080060std::unique_ptr<IArchiveWriter> CreateDirectoryArchiveWriter(IDiagnostics* diag,
61 const android::StringPiece& path);
Adam Lesinski1ab598f2015-08-14 14:26:04 -070062
Adam Lesinskid5083f62017-01-16 15:07:21 -080063std::unique_ptr<IArchiveWriter> CreateZipFileArchiveWriter(IDiagnostics* diag,
64 const android::StringPiece& path);
Adam Lesinski1ab598f2015-08-14 14:26:04 -070065
Adam Lesinskicacb28f2016-10-19 12:18:14 -070066} // namespace aapt
Adam Lesinski1ab598f2015-08-14 14:26:04 -070067
68#endif /* AAPT_FLATTEN_ARCHIVE_H */