blob: 46cd0ac0adc274c7a13e6f61ba337707e2468d7b [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 Lesinskia40e9722015-11-24 19:11:46 -080020#include "Diagnostics.h"
Adam Lesinski1ab598f2015-08-14 14:26:04 -070021#include "util/BigBuffer.h"
22#include "util/Files.h"
23#include "util/StringPiece.h"
24
Adam Lesinski59e04c62016-02-04 15:59:23 -080025#include <google/protobuf/io/zero_copy_stream_impl_lite.h>
Adam Lesinski1ab598f2015-08-14 14:26:04 -070026#include <fstream>
27#include <memory>
28#include <string>
29#include <vector>
30
31namespace aapt {
32
33struct ArchiveEntry {
Adam Lesinskicacb28f2016-10-19 12:18:14 -070034 enum : uint32_t {
35 kCompress = 0x01,
36 kAlign = 0x02,
37 };
Adam Lesinski1ab598f2015-08-14 14:26:04 -070038
Adam Lesinskicacb28f2016-10-19 12:18:14 -070039 std::string path;
40 uint32_t flags;
41 size_t uncompressedSize;
Adam Lesinski1ab598f2015-08-14 14:26:04 -070042};
43
Adam Lesinski5eeaadd2016-08-25 12:26:56 -070044class IArchiveWriter : public google::protobuf::io::CopyingOutputStream {
Adam Lesinskicacb28f2016-10-19 12:18:14 -070045 public:
46 virtual ~IArchiveWriter() = default;
Adam Lesinski1ab598f2015-08-14 14:26:04 -070047
Adam Lesinskicacb28f2016-10-19 12:18:14 -070048 virtual bool startEntry(const StringPiece& path, uint32_t flags) = 0;
49 virtual bool writeEntry(const BigBuffer& buffer) = 0;
50 virtual bool writeEntry(const void* data, size_t len) = 0;
51 virtual bool finishEntry() = 0;
Adam Lesinski59e04c62016-02-04 15:59:23 -080052
Adam Lesinskicacb28f2016-10-19 12:18:14 -070053 // CopyingOutputStream implementations.
54 bool Write(const void* buffer, int size) override {
55 return writeEntry(buffer, size);
56 }
Adam Lesinski1ab598f2015-08-14 14:26:04 -070057};
58
Adam Lesinskicacb28f2016-10-19 12:18:14 -070059std::unique_ptr<IArchiveWriter> createDirectoryArchiveWriter(
60 IDiagnostics* diag, const StringPiece& path);
Adam Lesinski1ab598f2015-08-14 14:26:04 -070061
Adam Lesinskicacb28f2016-10-19 12:18:14 -070062std::unique_ptr<IArchiveWriter> createZipFileArchiveWriter(
63 IDiagnostics* diag, const StringPiece& path);
Adam Lesinski1ab598f2015-08-14 14:26:04 -070064
Adam Lesinskicacb28f2016-10-19 12:18:14 -070065} // namespace aapt
Adam Lesinski1ab598f2015-08-14 14:26:04 -070066
67#endif /* AAPT_FLATTEN_ARCHIVE_H */