Struct GzEncoder

pub struct GzEncoder<W: Write> { /* private fields */ }

A gzip streaming encoder

This structure exposes a Write interface that will emit compressed data to the underlying writer W.

Examples

use std::io::prelude::*;
use flate2::Compression;
use flate2::write::GzEncoder;

// Vec<u8> implements Write to print the compressed bytes of sample string
# fn main() {

let mut e = GzEncoder::new(Vec::new(), Compression::default());
e.write_all(b"Hello World").unwrap();
println!("{:?}", e.finish().unwrap());
# }

Implementations

impl<W: Write> GzEncoder<W>

fn new(w: W, level: Compression) -> GzEncoder<W>

Creates a new encoder which will use the given compression level.

The encoder is not configured specially for the emitted header. For header configuration, see the GzBuilder type.

The data written to the returned encoder will be compressed and then written to the stream w.

fn get_ref(&self) -> &W

Acquires a reference to the underlying writer.

fn get_mut(&mut self) -> &mut W

Acquires a mutable reference to the underlying writer.

Note that mutation of the writer may result in surprising results if this encoder is continued to be used.

fn try_finish(&mut self) -> Result<()>

Attempt to finish this output stream, writing out final chunks of data.

Note that this function can only be used once data has finished being written to the output stream. After this function is called then further calls to write may result in a panic.

Panics

Attempts to write data to this stream may result in a panic after this function is called.

Errors

This function will perform I/O to complete this stream, and any I/O errors which occur will be returned from this function.

fn finish(self) -> Result<W>

Finish encoding this stream, returning the underlying writer once the encoding is done.

Note that this function may not be suitable to call in a situation where the underlying stream is an asynchronous I/O stream. To finish a stream the try_finish (or shutdown) method should be used instead. To re-acquire ownership of a stream it is safe to call this method after try_finish or shutdown has returned Ok.

Errors

This function will perform I/O to complete this stream, and any I/O errors which occur will be returned from this function.

Trait Implementations

impl<R: Read + Write> Read for GzEncoder<R>

fn read(&mut self, buf: &mut [u8]) -> Result<usize>

impl<W: Debug + Write> Debug for GzEncoder<W>

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

impl<W: Write> Drop for GzEncoder<W>

fn drop(&mut self)

impl<W: Write> Write for GzEncoder<W>

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

Auto Trait Implementations

impl<W> !UnwindSafe for GzEncoder<W>

impl<W> Freeze for GzEncoder<W> where Writer<W, Compress>: Freeze,

impl<W> RefUnwindSafe for GzEncoder<W> where Writer<W, Compress>: RefUnwindSafe,

impl<W> Send for GzEncoder<W> where Writer<W, Compress>: Send,

impl<W> Sync for GzEncoder<W> where Writer<W, Compress>: Sync,

impl<W> Unpin for GzEncoder<W> where Writer<W, Compress>: Unpin,

impl<W> UnsafeUnpin for GzEncoder<W> where Writer<W, Compress>: UnsafeUnpin,

Blanket Implementations

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

fn type_id(&self) -> TypeId

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

fn borrow(&self) -> &T

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

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

impl<T> From<T> for GzEncoder<W>

fn from(t: T) -> T

Returns the argument unchanged.

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

fn into(self) -> U

Calls U::from(self).

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

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

type Error = never;
fn try_from(value: U) -> Result<T, never>

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

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