Andrew de los Reyes | 8006106 | 2010-02-04 14:25:00 -0800 | [diff] [blame] | 1 | // Copyright (c) 2009 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 | |
Gilad Arnold | cf175a0 | 2014-07-10 16:48:47 -0700 | [diff] [blame] | 5 | #ifndef UPDATE_ENGINE_BZIP_EXTENT_WRITER_H_ |
| 6 | #define UPDATE_ENGINE_BZIP_EXTENT_WRITER_H_ |
Andrew de los Reyes | 8006106 | 2010-02-04 14:25:00 -0800 | [diff] [blame] | 7 | |
Andrew de los Reyes | 8006106 | 2010-02-04 14:25:00 -0800 | [diff] [blame] | 8 | #include <bzlib.h> |
Alex Vakulenko | f68bbbc | 2015-02-09 12:53:18 -0800 | [diff] [blame^] | 9 | #include <vector> |
| 10 | |
| 11 | #include <chromeos/secure_blob.h> |
| 12 | |
Andrew de los Reyes | 8006106 | 2010-02-04 14:25:00 -0800 | [diff] [blame] | 13 | #include "update_engine/extent_writer.h" |
| 14 | #include "update_engine/utils.h" |
| 15 | |
| 16 | // BzipExtentWriter is a concrete ExtentWriter subclass that bzip-decompresses |
| 17 | // what it's given in Write. It passes the decompressed data to an underlying |
| 18 | // ExtentWriter. |
| 19 | |
| 20 | namespace chromeos_update_engine { |
| 21 | |
| 22 | class BzipExtentWriter : public ExtentWriter { |
| 23 | public: |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 24 | explicit BzipExtentWriter(ExtentWriter* next) : next_(next) { |
Andrew de los Reyes | 8006106 | 2010-02-04 14:25:00 -0800 | [diff] [blame] | 25 | memset(&stream_, 0, sizeof(stream_)); |
| 26 | } |
| 27 | ~BzipExtentWriter() {} |
| 28 | |
Nam T. Nguyen | f1d582e | 2014-12-08 15:07:17 -0800 | [diff] [blame] | 29 | bool Init(FileDescriptorPtr fd, |
| 30 | const std::vector<Extent>& extents, |
| 31 | uint32_t block_size); |
Andrew de los Reyes | 8006106 | 2010-02-04 14:25:00 -0800 | [diff] [blame] | 32 | bool Write(const void* bytes, size_t count); |
| 33 | bool EndImpl(); |
| 34 | |
| 35 | private: |
| 36 | ExtentWriter* const next_; // The underlying ExtentWriter. |
| 37 | bz_stream stream_; // the libbz2 stream |
Alex Vakulenko | f68bbbc | 2015-02-09 12:53:18 -0800 | [diff] [blame^] | 38 | chromeos::Blob input_buffer_; |
Andrew de los Reyes | 8006106 | 2010-02-04 14:25:00 -0800 | [diff] [blame] | 39 | }; |
| 40 | |
| 41 | } // namespace chromeos_update_engine |
| 42 | |
Gilad Arnold | cf175a0 | 2014-07-10 16:48:47 -0700 | [diff] [blame] | 43 | #endif // UPDATE_ENGINE_BZIP_EXTENT_WRITER_H_ |