• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright (C) 2020 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 #pragma once
18 
19 #include <libsnapshot/cow_reader.h>
20 
21 namespace android {
22 namespace snapshot {
23 
24 class IByteStream {
25   public:
~IByteStream()26     virtual ~IByteStream() {}
27 
28     // Read up to |length| bytes, storing the number of bytes read in the out-
29     // parameter. If the end of the stream is reached, 0 is returned.
30     virtual bool Read(void* buffer, size_t length, size_t* read) = 0;
31 
32     // Size of the stream.
33     virtual size_t Size() const = 0;
34 };
35 
36 class IDecompressor {
37   public:
~IDecompressor()38     virtual ~IDecompressor() {}
39 
40     // Factory methods for decompression methods.
41     static std::unique_ptr<IDecompressor> Uncompressed();
42     static std::unique_ptr<IDecompressor> Gz();
43     static std::unique_ptr<IDecompressor> Brotli();
44 
45     // |output_bytes| is the expected total number of bytes to sink.
46     virtual bool Decompress(size_t output_bytes) = 0;
47 
set_stream(IByteStream * stream)48     void set_stream(IByteStream* stream) { stream_ = stream; }
set_sink(IByteSink * sink)49     void set_sink(IByteSink* sink) { sink_ = sink; }
50 
51   protected:
52     IByteStream* stream_ = nullptr;
53     IByteSink* sink_ = nullptr;
54 };
55 
56 }  // namespace snapshot
57 }  // namespace android
58