[go: up one dir, main page]

Struct Encoder

Source
pub struct Encoder<W: BitWriter> { /* private fields */ }
Expand description

LZW encoder using the algorithm of GIF files.

Implementations§

Source§

impl<W: BitWriter> Encoder<W>

Source

pub fn new(w: W, min_code_size: u8) -> Result<Encoder<W>>

Creates a new LZW encoder.

Note: If min_code_size < 8 then Self::encode_bytes might panic when the supplied data containts values that exceed 1 << min_code_size.

Examples found in repository?
examples/lzw-compress.rs (line 10)
7fn main() {
8    match (|| -> io::Result<()> {
9        let mut encoder = try!(
10            lzw::Encoder::new(lzw::LsbWriter::new(io::stdout()), 8)
11        );
12        let stdin = io::stdin();
13        let mut stdin = stdin.lock();
14        loop {
15            let len = {
16                let buf = try!(stdin.fill_buf());
17                try!(encoder.encode_bytes(buf));
18                buf.len()
19            };
20            if len == 0 {
21                break
22            }
23            stdin.consume(len);
24        }
25        Ok(())
26    })() {
27        Ok(()) => (),
28        Err(err) => { let _ = write!(io::stderr(), "{}", err); }
29    }
30    
31}
Source

pub fn encode_bytes(&mut self, bytes: &[u8]) -> Result<()>

Compresses bytes and writes the result into the writer.

§Panics

This function might panic if any of the input bytes exceeds 1 << min_code_size. This cannot happen if min_code_size >= 8.

Examples found in repository?
examples/lzw-compress.rs (line 17)
7fn main() {
8    match (|| -> io::Result<()> {
9        let mut encoder = try!(
10            lzw::Encoder::new(lzw::LsbWriter::new(io::stdout()), 8)
11        );
12        let stdin = io::stdin();
13        let mut stdin = stdin.lock();
14        loop {
15            let len = {
16                let buf = try!(stdin.fill_buf());
17                try!(encoder.encode_bytes(buf));
18                buf.len()
19            };
20            if len == 0 {
21                break
22            }
23            stdin.consume(len);
24        }
25        Ok(())
26    })() {
27        Ok(()) => (),
28        Err(err) => { let _ = write!(io::stderr(), "{}", err); }
29    }
30    
31}

Trait Implementations§

Source§

impl<W: BitWriter> Drop for Encoder<W>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<W> Freeze for Encoder<W>
where W: Freeze,

§

impl<W> RefUnwindSafe for Encoder<W>
where W: RefUnwindSafe,

§

impl<W> Send for Encoder<W>
where W: Send,

§

impl<W> Sync for Encoder<W>
where W: Sync,

§

impl<W> Unpin for Encoder<W>
where W: Unpin,

§

impl<W> UnwindSafe for Encoder<W>
where W: UnwindSafe,

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>,

Source§

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>,

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.