1#ifndef BYTEME_GZIP_FILE_WRITER_HPP
2#define BYTEME_GZIP_FILE_WRITER_HPP
9#include "check_buffer_size.hpp"
50 if (gzsetparams(my_gzfile.handle, options.
compression_level, Z_DEFAULT_STRATEGY) != Z_OK) {
51 throw std::runtime_error(
"failed to set the Gzip compression parameters");
58 void write(
const unsigned char* buffer, std::size_t n) {
59 safe_write<unsigned, true>(
62 [&](
const unsigned char* buffer0,
unsigned n0) ->
void {
63 auto ok = gzwrite(my_gzfile.handle, buffer0, n0);
65 throw std::runtime_error(
"failed to write to the Gzip-compressed file");
72 my_gzfile.closed =
true;
73 if (gzclose(my_gzfile.handle) != Z_OK) {
74 throw std::runtime_error(
"failed to close the Gzip-compressed file after writing");
79 SelfClosingGzFile my_gzfile;
Write uncompressed bytes to a Gzip-compressed file.
Definition GzipFileWriter.hpp:42
void write(const unsigned char *buffer, std::size_t n)
Definition GzipFileWriter.hpp:58
GzipFileWriter(const char *path, const GzipFileWriterOptions &options)
Definition GzipFileWriter.hpp:48
void finish()
Definition GzipFileWriter.hpp:71
Virtual class for writing bytes to a sink.
Definition Writer.hpp:21
virtual void write(const unsigned char *buffer, std::size_t n)=0
Simple byte readers and writers.
Options for GzipFileWriter construction.
Definition GzipFileWriter.hpp:22
int compression_level
Definition GzipFileWriter.hpp:27
std::optional< unsigned > gzbuffer_size
Definition GzipFileWriter.hpp:34