1 /*
2  * Copyright (C) 2019 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 #pragma once
17 
18 #include <string>
19 #include <vector>
20 
21 #include "common/libs/utils/result.h"
22 
23 namespace cuttlefish {
24 
25 // Operations on archive files
26 class Archive {
27   std::string file_;
28 
29  public:
30   Archive(const std::string& file);
31   ~Archive();
32 
33   std::vector<std::string> Contents();
34   bool ExtractAll(const std::string& target_directory = ".");
35   bool ExtractFiles(const std::vector<std::string>& files,
36                     const std::string& target_directory = ".");
37   std::string ExtractToMemory(const std::string& path);
38 };
39 
40 Result<std::vector<std::string>> ExtractImages(
41     const std::string& archive_filepath, const std::string& target_directory,
42     const std::vector<std::string>& images, const bool keep_archive);
43 
44 Result<std::string> ExtractImage(const std::string& archive_filepath,
45                                  const std::string& target_directory,
46                                  const std::string& image,
47                                  const bool keep_archive = true);
48 
49 Result<std::vector<std::string>> ExtractArchiveContents(
50     const std::string& archive_filepath, const std::string& target_directory,
51     const bool keep_archive);
52 
53 } // namespace cuttlefish
54