DivansBrotliHybridCompressorWriter

Struct DivansBrotliHybridCompressorWriter 

Source
pub struct DivansBrotliHybridCompressorWriter<W: Write>(/* private fields */);

Implementations§

Source§

impl<W: Write> DivansBrotliHybridCompressorWriter<W>

Source

pub fn new(writer: W, opts: DivansCompressorOptions, buffer_size: usize) -> Self

Examples found in repository?
examples/compress.rs (lines 13-34)
7fn main() {
8    let example_opts = divans::DivansCompressorOptions::default();
9    use std::io;
10    let stdout = &mut io::stdout();
11    {
12        use std::io::{Read, Write};
13        let mut writer = divans::DivansBrotliHybridCompressorWriter::new(
14            stdout,
15            divans::DivansCompressorOptions{
16                brotli_literal_byte_score:example_opts.brotli_literal_byte_score,
17                force_literal_context_mode:example_opts.force_literal_context_mode,
18                literal_adaptation:example_opts.literal_adaptation, // should we override how fast the cdfs converge for literals?
19                window_size:example_opts.window_size, // log 2 of the window size
20                lgblock:example_opts.lgblock, // should we override how often metablocks are created in brotli
21                quality:example_opts.quality, // the quality of brotli commands
22                q9_5:example_opts.q9_5,
23                dynamic_context_mixing:example_opts.dynamic_context_mixing, // if we want to mix together the stride prediction and the context map
24                prior_depth:example_opts.prior_depth,
25                use_brotli:example_opts.use_brotli, // ignored
26                use_context_map:example_opts.use_context_map, // whether we should use the brotli context map in addition to the last 8 bits of each byte as a prior
27                force_stride_value: example_opts.force_stride_value, // if we should use brotli to decide on the stride
28                speed_detection_quality: example_opts.speed_detection_quality,
29                stride_detection_quality: example_opts.stride_detection_quality,
30                prior_bitmask_detection: example_opts.prior_bitmask_detection,
31                divans_ir_optimizer:example_opts.divans_ir_optimizer,
32            },
33            4096, // internal buffer size
34        );
35        let mut buf = [0u8; 4096];
36        loop {
37            match io::stdin().read(&mut buf[..]) {
38                Err(e) => {
39                    if let io::ErrorKind::Interrupted = e.kind() {
40                        continue;
41                    }
42                    panic!(e);
43                }
44                Ok(size) => {
45                    if size == 0 {
46                        match writer.flush() {
47                            Err(e) => {
48                                if let io::ErrorKind::Interrupted = e.kind() {
49                                    continue;
50                                }
51                                panic!(e)
52                            }
53                            Ok(_) => break,
54                        }
55                    }
56                    match writer.write_all(&buf[..size]) {
57                        Err(e) => panic!(e),
58                        Ok(_) => {},
59                    }
60                }
61            }
62        }
63    }
64}

Trait Implementations§

Source§

impl<W: Write> Write for DivansBrotliHybridCompressorWriter<W>

Source§

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

Writes a buffer into this writer, returning how many bytes were written. Read more
Source§

fn flush(&mut self) -> Result<(), Error>

Flushes this output stream, ensuring that all intermediately buffered contents reach their destination. Read more
1.36.0 · Source§

fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> Result<usize, Error>

Like write, except that it writes from a slice of buffers. Read more
Source§

fn is_write_vectored(&self) -> bool

🔬This is a nightly-only experimental API. (can_vector)
Determines if this Writer has an efficient write_vectored implementation. Read more
1.0.0 · Source§

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

Attempts to write an entire buffer into this writer. Read more
Source§

fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>

🔬This is a nightly-only experimental API. (write_all_vectored)
Attempts to write multiple buffers into this writer. Read more
1.0.0 · Source§

fn write_fmt(&mut self, args: Arguments<'_>) -> Result<(), Error>

Writes a formatted string into this writer, returning any error encountered. Read more
1.0.0 · Source§

fn by_ref(&mut self) -> &mut Self
where Self: Sized,

Creates a “by reference” adapter for this instance of Write. Read more

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