Struct ggstd::compress::zlib::Writer

source ·
pub struct Writer<'a> { /* private fields */ }
Expand description

A Writer takes data written to it and writes the compressed form of that data to an underlying writer (see new_writer).

Implementations§

source§

impl<'a> Writer<'a>

source

pub fn reset(&mut self, w: &'a mut dyn Write)

reset clears the state of the Writer z such that it is equivalent to its initial state from new_writer_level or new_writer_level_dict, but instead writing to w.

source

pub fn write(&mut self, p: &[u8]) -> Result<usize>

write writes a compressed form of p to the underlying writer. The compressed bytes are not necessarily flushed until the Writer is closed or explicitly flushed.

Examples found in repository?
examples/zlib-writer.rs (line 7)
4
5
6
7
8
9
10
11
fn main() {
    let mut b = bytes::Buffer::new();
    let mut w = zlib::new_writer(&mut b);
    w.write("hello, world\n".as_bytes()).unwrap();
    w.close().unwrap();
    println!("{:?}", b.bytes());
    // Output: [120 156 202 72 205 201 201 215 81 40 207 47 202 73 225 2 4 0 0 255 255 33 231 4 147]
}
source

pub fn flush(&'a mut self) -> Result<()>

flush flushes the Writer to its underlying ggio::Writer.

source

pub fn close(&mut self) -> Result<()>

close closes the Writer, flushing any unwritten data to the underlying writer, but does not close the underlying writer.

Examples found in repository?
examples/zlib-writer.rs (line 8)
4
5
6
7
8
9
10
11
fn main() {
    let mut b = bytes::Buffer::new();
    let mut w = zlib::new_writer(&mut b);
    w.write("hello, world\n".as_bytes()).unwrap();
    w.close().unwrap();
    println!("{:?}", b.bytes());
    // Output: [120 156 202 72 205 201 201 215 81 40 207 47 202 73 225 2 4 0 0 255 255 33 231 4 147]
}

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for Writer<'a>

§

impl<'a> !Send for Writer<'a>

§

impl<'a> !Sync for Writer<'a>

§

impl<'a> Unpin for Writer<'a>

§

impl<'a> !UnwindSafe for Writer<'a>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere 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 Twhere 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.