Home | History | Annotate | Download | only in bsdiff
      1 // Copyright 2017 The Chromium OS Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef _BSDIFF_DECOMPRESSOR_INTERFACE_H_
      6 #define _BSDIFF_DECOMPRESSOR_INTERFACE_H_
      7 
      8 #include <stddef.h>
      9 #include <stdint.h>
     10 
     11 #include <memory>
     12 
     13 #include "bsdiff/constants.h"
     14 
     15 namespace bsdiff {
     16 
     17 class DecompressorInterface {
     18  public:
     19   virtual ~DecompressorInterface() {}
     20 
     21   // Set the buffer starting from |input_data| with length |size| as the input
     22   // compressed stream. This buffer is owned by the caller and should stay
     23   // valid until the Close() function is called.
     24   virtual bool SetInputData(const uint8_t* input_data, size_t size) = 0;
     25 
     26   // Decompress the stream and output |bytes_to_output| bytes of data to
     27   // |output_data|. Returns false if not all bytes_to_output can be
     28   // decompressed from the stream due to a decompressor error or EOF.
     29   virtual bool Read(uint8_t* output_data, size_t bytes_to_output) = 0;
     30 
     31   // Close the decompression stream.
     32   virtual bool Close() = 0;
     33 };
     34 
     35 std::unique_ptr<DecompressorInterface> CreateDecompressor(CompressorType type);
     36 
     37 }  // namespace bsdiff
     38 #endif  // _BSDIFF_DECOMPRESSOR_INTERFACE_H_
     39