blob: 0187c0b2a604d5ad2a430d8f90492e2fcbd4764b [file] [log] [blame]
Andrew de los Reyes80061062010-02-04 14:25:00 -08001// 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 Arnoldcf175a02014-07-10 16:48:47 -07005#ifndef UPDATE_ENGINE_BZIP_EXTENT_WRITER_H_
6#define UPDATE_ENGINE_BZIP_EXTENT_WRITER_H_
Andrew de los Reyes80061062010-02-04 14:25:00 -08007
8#include <vector>
9#include <bzlib.h>
10#include "update_engine/extent_writer.h"
11#include "update_engine/utils.h"
12
13// BzipExtentWriter is a concrete ExtentWriter subclass that bzip-decompresses
14// what it's given in Write. It passes the decompressed data to an underlying
15// ExtentWriter.
16
17namespace chromeos_update_engine {
18
19class BzipExtentWriter : public ExtentWriter {
20 public:
Alex Vakulenkod2779df2014-06-16 13:19:00 -070021 explicit BzipExtentWriter(ExtentWriter* next) : next_(next) {
Andrew de los Reyes80061062010-02-04 14:25:00 -080022 memset(&stream_, 0, sizeof(stream_));
23 }
24 ~BzipExtentWriter() {}
25
Nam T. Nguyenf1d582e2014-12-08 15:07:17 -080026 bool Init(FileDescriptorPtr fd,
27 const std::vector<Extent>& extents,
28 uint32_t block_size);
Andrew de los Reyes80061062010-02-04 14:25:00 -080029 bool Write(const void* bytes, size_t count);
30 bool EndImpl();
31
32 private:
33 ExtentWriter* const next_; // The underlying ExtentWriter.
34 bz_stream stream_; // the libbz2 stream
35 std::vector<char> input_buffer_;
36};
37
38} // namespace chromeos_update_engine
39
Gilad Arnoldcf175a02014-07-10 16:48:47 -070040#endif // UPDATE_ENGINE_BZIP_EXTENT_WRITER_H_