pub struct GzBuilder { /* private fields */ }
Expand description
A builder structure to create a new gzip Encoder.
This structure controls header configuration options such as the filename.
Examples
use std::io::prelude::*;
use std::fs::File;
use flate2::GzBuilder;
use flate2::Compression;
// GzBuilder opens a file and writes a sample string using GzBuilder pattern
let f = File::create("examples/hello_world.gz")?;
let mut gz = GzBuilder::new()
.filename("hello_world.txt")
.comment("test file, please delete")
.write(f, Compression::default());
gz.write_all(b"hello world")?;
gz.finish()?;
Implementations
sourceimpl GzBuilder
impl GzBuilder
sourcepub fn operating_system(self, os: u8) -> GzBuilder
pub fn operating_system(self, os: u8) -> GzBuilder
Configure the operating_system
field in the gzip header.
sourcepub fn extra<T: Into<Vec<u8>>>(self, extra: T) -> GzBuilder
pub fn extra<T: Into<Vec<u8>>>(self, extra: T) -> GzBuilder
Configure the extra
field in the gzip header.
sourcepub fn filename<T: Into<Vec<u8>>>(self, filename: T) -> GzBuilder
pub fn filename<T: Into<Vec<u8>>>(self, filename: T) -> GzBuilder
Configure the filename
field in the gzip header.
Panics
Panics if the filename
slice contains a zero.
sourcepub fn write<W: Write>(self, w: W, lvl: Compression) -> GzEncoder<W>ⓘNotable traits for GzEncoder<W>impl<W: Write> Write for GzEncoder<W>impl<R: Read + Write> Read for GzEncoder<R>
pub fn write<W: Write>(self, w: W, lvl: Compression) -> GzEncoder<W>ⓘNotable traits for GzEncoder<W>impl<W: Write> Write for GzEncoder<W>impl<R: Read + Write> Read for GzEncoder<R>
Consume this builder, creating a writer encoder in the process.
The data written to the returned encoder will be compressed and then
written out to the supplied parameter w
.
sourcepub fn read<R: Read>(self, r: R, lvl: Compression) -> GzEncoder<R>ⓘNotable traits for GzEncoder<R>impl<R: Read> Read for GzEncoder<R>impl<R: Read + Write> Write for GzEncoder<R>
pub fn read<R: Read>(self, r: R, lvl: Compression) -> GzEncoder<R>ⓘNotable traits for GzEncoder<R>impl<R: Read> Read for GzEncoder<R>impl<R: Read + Write> Write for GzEncoder<R>
Consume this builder, creating a reader encoder in the process.
Data read from the returned encoder will be the compressed version of the data read from the given reader.
sourcepub fn buf_read<R>(self, r: R, lvl: Compression) -> GzEncoder<R>ⓘNotable traits for GzEncoder<R>impl<R: BufRead> Read for GzEncoder<R>impl<R: BufRead + Write> Write for GzEncoder<R>
where
R: BufRead,
pub fn buf_read<R>(self, r: R, lvl: Compression) -> GzEncoder<R>ⓘNotable traits for GzEncoder<R>impl<R: BufRead> Read for GzEncoder<R>impl<R: BufRead + Write> Write for GzEncoder<R>
where
R: BufRead,
Consume this builder, creating a reader encoder in the process.
Data read from the returned encoder will be the compressed version of the data read from the given reader.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for GzBuilder
impl Send for GzBuilder
impl Sync for GzBuilder
impl Unpin for GzBuilder
impl UnwindSafe for GzBuilder
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more