#[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
impl GzipHeader
Sourcepub fn new() -> Self
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);Sourcepub fn with_name(self, name: &[u8]) -> Self
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"[..]));Sourcepub fn with_comment(self, comment: &[u8]) -> Self
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"[..]));Sourcepub fn with_extra(self, extra: &[u8]) -> Self
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));Sourcepub fn with_mtime(self, mtime: u32) -> Self
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);Sourcepub fn with_os(self, os: u8) -> Self
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);Sourcepub fn with_text(self, text: bool) -> Self
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());Sourcepub fn extra_flags(&self) -> u8
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);Trait Implementations§
Source§impl Clone for GzipHeader
impl Clone for GzipHeader
Source§impl Debug for GzipHeader
impl Debug for GzipHeader
Source§impl Default for GzipHeader
impl Default for GzipHeader
impl Eq for GzipHeader
Source§impl PartialEq for GzipHeader
impl PartialEq for GzipHeader
impl StructuralPartialEq for GzipHeader
Auto Trait Implementations§
impl Forget for GzipHeader
impl Freeze for GzipHeader
impl RefUnwindSafe for GzipHeader
impl Send for GzipHeader
impl Sync for GzipHeader
impl Unpin for GzipHeader
impl UnsafeUnpin for GzipHeader
impl UnwindSafe for GzipHeader
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more