blob: 6a6133ac4dedddad11d47cef9f6bcb71232a98cf [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
Andrew de los Reyes80061062010-02-04 14:25:00 -08008#include <bzlib.h>
Alex Vakulenkof68bbbc2015-02-09 12:53:18 -08009#include <vector>
10
11#include <chromeos/secure_blob.h>
12
Andrew de los Reyes80061062010-02-04 14:25:00 -080013#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
20namespace chromeos_update_engine {
21
22class BzipExtentWriter : public ExtentWriter {
23 public:
Alex Vakulenkod2779df2014-06-16 13:19:00 -070024 explicit BzipExtentWriter(ExtentWriter* next) : next_(next) {
Andrew de los Reyes80061062010-02-04 14:25:00 -080025 memset(&stream_, 0, sizeof(stream_));
26 }
27 ~BzipExtentWriter() {}
28
Nam T. Nguyenf1d582e2014-12-08 15:07:17 -080029 bool Init(FileDescriptorPtr fd,
30 const std::vector<Extent>& extents,
31 uint32_t block_size);
Andrew de los Reyes80061062010-02-04 14:25:00 -080032 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 Vakulenkof68bbbc2015-02-09 12:53:18 -080038 chromeos::Blob input_buffer_;
Andrew de los Reyes80061062010-02-04 14:25:00 -080039};
40
41} // namespace chromeos_update_engine
42
Gilad Arnoldcf175a02014-07-10 16:48:47 -070043#endif // UPDATE_ENGINE_BZIP_EXTENT_WRITER_H_