Archive.h revision ce5e56e243d262a9b65459c3bd0bb9eaadd40628
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 <fstream>
21#include <memory>
22#include <string>
23#include <vector>
24
25#include "google/protobuf/io/zero_copy_stream_impl_lite.h"
26
27#include "Diagnostics.h"
28#include "util/BigBuffer.h"
29#include "util/Files.h"
30#include "util/StringPiece.h"
31
32namespace aapt {
33
34struct ArchiveEntry {
35  enum : uint32_t {
36    kCompress = 0x01,
37    kAlign = 0x02,
38  };
39
40  std::string path;
41  uint32_t flags;
42  size_t uncompressed_size;
43};
44
45class IArchiveWriter : public google::protobuf::io::CopyingOutputStream {
46 public:
47  virtual ~IArchiveWriter() = default;
48
49  virtual bool StartEntry(const StringPiece& path, uint32_t flags) = 0;
50  virtual bool WriteEntry(const BigBuffer& buffer) = 0;
51  virtual bool WriteEntry(const void* data, size_t len) = 0;
52  virtual bool FinishEntry() = 0;
53
54  // CopyingOutputStream implementations.
55  bool Write(const void* buffer, int size) override {
56    return WriteEntry(buffer, size);
57  }
58};
59
60std::unique_ptr<IArchiveWriter> CreateDirectoryArchiveWriter(
61    IDiagnostics* diag, const StringPiece& path);
62
63std::unique_ptr<IArchiveWriter> CreateZipFileArchiveWriter(
64    IDiagnostics* diag, const StringPiece& path);
65
66}  // namespace aapt
67
68#endif /* AAPT_FLATTEN_ARCHIVE_H */
69