AU: Extent writer utility classes
These are similar to the FileWriter classes, but focus on writing to
extents within a file (or device) rather than writing a file in order.
Again there is a ExtentWriter interface from which all types of extent
writers interit.
There are also two basic extent writers: a direct extent writer that
writes data directly to the file descriptor, and a zero padding extent
writer that piggy-backs on another extent writer. When the
zero-padding extent writer is End()ed, it fills out the rest of the
extent with zeros.
Also, BzipExtentWriter: an ExtentWriter concrete subclass that writes
to another ExtentWriter. BzipExtentWriter bzip2 decompresses all data
passed through.
Review URL: http://codereview.chromium.org/551132
diff --git a/bzip_extent_writer.h b/bzip_extent_writer.h
new file mode 100644
index 0000000..fdd9671
--- /dev/null
+++ b/bzip_extent_writer.h
@@ -0,0 +1,38 @@
+// Copyright (c) 2009 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_BZIP_EXTENT_WRITER_H__
+#define CHROMEOS_PLATFORM_UPDATE_ENGINE_BZIP_EXTENT_WRITER_H__
+
+#include <vector>
+#include <bzlib.h>
+#include "update_engine/extent_writer.h"
+#include "update_engine/utils.h"
+
+// BzipExtentWriter is a concrete ExtentWriter subclass that bzip-decompresses
+// what it's given in Write. It passes the decompressed data to an underlying
+// ExtentWriter.
+
+namespace chromeos_update_engine {
+
+class BzipExtentWriter : public ExtentWriter {
+ public:
+ BzipExtentWriter(ExtentWriter* next) : next_(next) {
+ memset(&stream_, 0, sizeof(stream_));
+ }
+ ~BzipExtentWriter() {}
+
+ bool Init(int fd, const std::vector<Extent>& extents, uint32 block_size);
+ bool Write(const void* bytes, size_t count);
+ bool EndImpl();
+
+ private:
+ ExtentWriter* const next_; // The underlying ExtentWriter.
+ bz_stream stream_; // the libbz2 stream
+ std::vector<char> input_buffer_;
+};
+
+} // namespace chromeos_update_engine
+
+#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_BZIP_EXTENT_WRITER_H__