1#ifndef BYTEME_GZIP_FILE_WRITER_HPP
2#define BYTEME_GZIP_FILE_WRITER_HPP
29 GzipFileWriter(
const char* path,
int compression_level = 6,
size_t buffer_size = 65536) : my_gzfile(path,
"wb") {
30 if (gzbuffer(my_gzfile.handle, buffer_size)) {
31 throw std::runtime_error(
"failed to set the Gzip compression buffer");
33 if (gzsetparams(my_gzfile.handle, compression_level, Z_DEFAULT_STRATEGY) != Z_OK) {
34 throw std::runtime_error(
"failed to set the Gzip compression parameters");
43 GzipFileWriter(
const std::string& path,
int compression_level = 6,
size_t buffer_size = 65536) :
GzipFileWriter(path.c_str(), compression_level, buffer_size) {}
48 void write(
const unsigned char* buffer,
size_t n) {
50 size_t ok = gzwrite(my_gzfile.handle, buffer, n);
52 throw std::runtime_error(
"failed to write to the Gzip-compressed file");
58 my_gzfile.closed =
true;
59 if (gzclose(my_gzfile.handle) != Z_OK) {
60 throw std::runtime_error(
"failed to close the Gzip-compressed file after writing");
65 SelfClosingGzFile my_gzfile;
Write uncompressed bytes to a Gzip-compressed file.
Definition GzipFileWriter.hpp:22
GzipFileWriter(const std::string &path, int compression_level=6, size_t buffer_size=65536)
Definition GzipFileWriter.hpp:43
void write(const unsigned char *buffer, size_t n)
Definition GzipFileWriter.hpp:48
GzipFileWriter(const char *path, int compression_level=6, size_t buffer_size=65536)
Definition GzipFileWriter.hpp:29
void finish()
Definition GzipFileWriter.hpp:57
Virtual class for writing bytes to a sink.
Definition Writer.hpp:18
virtual void write(const unsigned char *buffer, size_t n)=0
Simple byte readers and writers.