Skip to main content

GzipHeader

Struct GzipHeader 

Source
#[non_exhaustive]
pub struct GzipHeader { /* private fields */ }
Expand description

The fields of a gzip header.

Decoders fill it only when asked (Decoder::with_keep_header); the optional fields are bounded by Limits::max_header.

§Examples

use compress_lib::{Level, deflate::Flush, gzip::{self, GzipHeader}};

let header = GzipHeader::new().with_name(b"report.csv").with_mtime(1_700_000_000);
let mut enc = gzip::Encoder::new(Level::DEFAULT).with_header(header);
let mut packed = Vec::new();
enc.compress_vec(b"a,b\n1,2\n", &mut packed, Flush::Finish)?;

let mut dec = gzip::Decoder::new().with_keep_header(true);
let mut out = Vec::new();
dec.finish_vec(&packed, &mut out)?;
assert_eq!(dec.header().and_then(|h| h.name()), Some(&b"report.csv"[..]));

Implementations§

Source§

impl GzipHeader

Source

pub fn new() -> Self

No name, comment, or extra field; time stamp 0; OS “unknown”.

§Examples
assert_eq!(compress_lib::gzip::GzipHeader::new().os(), 255);
Source

pub fn with_name(self, name: &[u8]) -> Self

Sets the file name (written without its terminating zero; it must not contain one).

§Examples
let h = compress_lib::gzip::GzipHeader::new().with_name(b"a.txt");
assert_eq!(h.name(), Some(&b"a.txt"[..]));
Source

pub fn with_comment(self, comment: &[u8]) -> Self

Sets the comment (it must not contain a zero byte).

§Examples
let h = compress_lib::gzip::GzipHeader::new().with_comment(b"nightly export");
assert_eq!(h.comment(), Some(&b"nightly export"[..]));
Source

pub fn with_extra(self, extra: &[u8]) -> Self

Sets the extra field (at most 65,535 bytes; longer is cut).

§Examples
let h = compress_lib::gzip::GzipHeader::new().with_extra(b"AB\x02\x00hi");
assert_eq!(h.extra().map(<[u8]>::len), Some(6));
Source

pub fn with_mtime(self, mtime: u32) -> Self

Sets the modification time (Unix seconds; 0 means none).

§Examples
assert_eq!(compress_lib::gzip::GzipHeader::new().with_mtime(7).mtime(), 7);
Source

pub fn with_os(self, os: u8) -> Self

Sets the operating system byte (RFC 1952 section 2.3.1).

§Examples
assert_eq!(compress_lib::gzip::GzipHeader::new().with_os(3).os(), 3);
Source

pub fn with_text(self, text: bool) -> Self

Marks the data as probably text (FTEXT).

§Examples
assert!(compress_lib::gzip::GzipHeader::new().with_text(true).text());
Source

pub fn name(&self) -> Option<&[u8]>

The file name, if any.

§Examples
assert_eq!(compress_lib::gzip::GzipHeader::new().name(), None);
Source

pub fn comment(&self) -> Option<&[u8]>

The comment, if any.

§Examples
assert_eq!(compress_lib::gzip::GzipHeader::new().comment(), None);
Source

pub fn extra(&self) -> Option<&[u8]>

The extra field, if any.

§Examples
assert_eq!(compress_lib::gzip::GzipHeader::new().extra(), None);
Source

pub fn mtime(&self) -> u32

The modification time.

§Examples
assert_eq!(compress_lib::gzip::GzipHeader::new().mtime(), 0);
Source

pub fn os(&self) -> u8

The operating system byte.

§Examples
assert_eq!(compress_lib::gzip::GzipHeader::new().os(), 255);
Source

pub fn extra_flags(&self) -> u8

The extra flags byte (2: best compression, 4: fastest).

§Examples
assert_eq!(compress_lib::gzip::GzipHeader::new().extra_flags(), 0);
Source

pub fn text(&self) -> bool

Whether FTEXT is set.

§Examples
assert!(!compress_lib::gzip::GzipHeader::new().text());

Trait Implementations§

Source§

impl Clone for GzipHeader

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for GzipHeader

Source§

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

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

impl Default for GzipHeader

Source§

fn default() -> Self

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

impl Eq for GzipHeader

Source§

impl PartialEq for GzipHeader

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for GzipHeader

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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.