Struct flate2::GzBuilder

source ·
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§

source§

impl GzBuilder

source

pub fn new() -> GzBuilder

Create a new blank builder with no header by default.

source

pub fn mtime(self, mtime: u32) -> GzBuilder

Configure the mtime field in the gzip header.

source

pub fn operating_system(self, os: u8) -> GzBuilder

Configure the operating_system field in the gzip header.

source

pub fn extra<T: Into<Vec<u8>>>(self, extra: T) -> GzBuilder

Configure the extra field in the gzip header.

source

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.

source

pub fn comment<T: Into<Vec<u8>>>(self, comment: T) -> GzBuilder

Configure the comment field in the gzip header.

Panics

Panics if the comment slice contains a zero.

source

pub fn write<W: Write>(self, w: W, lvl: Compression) -> GzEncoder<W>

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.

source

pub fn read<R: Read>(self, r: R, lvl: Compression) -> 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.

source

pub fn buf_read<R>(self, r: R, lvl: Compression) -> 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§

source§

impl Debug for GzBuilder

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for GzBuilder

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.