Struct vpk0::Encoder [−][src]
Specify the encoding settings, such as window size, logging, input, and output
To create a new Encoder
, use for_reader()
, for_file()
, or for_bytes()
.
Then, change any of the encoding settings with Encoder
’s helper methods.
Finally, encode the input data with encode_to_writer()
, encode_to_file()
, or encode_to_vec()
.
let input = b"ABBACABBCADFEGABA"; let compressed = Encoder::for_bytes(input) .two_sample() .lzss_backend(LzssBackend::Kmp) .with_logging(&mut ::std::io::stdout()) .encode_to_vec();
The default encoding settings are as follows:
- One Sample encoding
- No user offset or length values
- No logging
- LZSS settings:
- 16 bit window (65536 bytes)
- 8 bit lookahead (256 bytes)
- Minimum match of 3 bytes
Brute
match searching
Implementations
impl<'a, R: Read> Encoder<'a, R>
[src]
pub fn for_reader(rdr: R) -> Self
[src]
Create a new Encoder
for the data in rdr
.
pub fn method(&mut self, method: VpkMethod) -> &mut Self
[src]
Set the encoded VPK file to use either a one sample offset lookback, or a two sample lookback.
In one sample mode, the offset value is directly encoded into the output. In two sample mode, the offset value is divided by four. Then the remainder (if necessary) and quotient are stored in the output.
pub fn one_sample(&mut self) -> &mut Self
[src]
Conveince method to set one sample encoding without importing VpkMethod
.
pub fn two_sample(&mut self) -> &mut Self
[src]
Conveince method to set two sample encoding without importing VpkMethod
.
pub fn with_lzss_settings(&mut self, settings: LzssSettings) -> &mut Self
[src]
Set the settings used for the underyling lzss compression. See LzssSettings
for more details.
pub fn lzss_backend(&mut self, backend: LzssBackend) -> &mut Self
[src]
Set the algorithm used to search for LZSS matches when encoding
pub fn with_offsets(&mut self, o: &'a str) -> &mut Self
[src]
Manually set the offset Huffman Tree with a text based representation of a tree.
This representation can be extracted from a vpk0
file by vpk_info
or Decoder::trees
.
let compressed = Encoder::for_bytes(b"sam I am I am sam") .with_offsets("(3, (7, 10))") .encode_to_vec();
Note that the encoding will fail if there is an offset whose size in bits is larger than the largest provided offset.
pub fn optional_offsets(&mut self, offsets: Option<&'a str>) -> &mut Self
[src]
Set the offset Huffman Tree if offsets.is_some()
,
else create the offset tree from the input data.
pub fn with_lengths(&mut self, l: &'a str) -> &mut Self
[src]
Manually set the length Huffman Tree with a text based representation of a tree.
This representation can be extracted from a vpk0
file by vpk_info
or Decoder::trees
.
let compressed = Encoder::for_bytes(b"sam I am I am sam") .with_lengths("((3, 5), (7, (12, 16))") .encode_to_vec();
Note that the encoding will fail if there is an offset whose size in bits is larger than the largest provided offset.
pub fn optional_lengths(&mut self, lengths: Option<&'a str>) -> &mut Self
[src]
Set the length Huffman Tree if offsets.is_some()
,
else create the offset tree from the input data.
pub fn with_logging<L: Write>(&mut self, log: &'a mut L) -> &mut Self
[src]
Write debugging and diagnotic information to log
while the input is
being encoded.
pub fn encode_to_writer<W: Write>(&mut self, wtr: W) -> Result<(), VpkError>
[src]
Start the encoding and write the compressed data out to wtr
pub fn encode_to_file<P: AsRef<Path>>(&mut self, f: P) -> Result<(), VpkError>
[src]
Start the encoding and write the compressed data out to the newly created
File
f
pub fn encode_to_vec(&mut self) -> Result<Vec<u8>, VpkError>
[src]
Start the encoding and return the compressed data in a Vec<u8>
.
impl<'a> Encoder<'a, BufReader<File>>
[src]
pub fn for_file<P: AsRef<Path>>(p: P) -> Result<Self, VpkError>
[src]
Create a new Encoder
for the file at p
.
impl<'a> Encoder<'a, Cursor<&'a [u8]>>
[src]
Auto Trait Implementations
impl<'a, R> !RefUnwindSafe for Encoder<'a, R>
impl<'a, R> !Send for Encoder<'a, R>
impl<'a, R> !Sync for Encoder<'a, R>
impl<'a, R> Unpin for Encoder<'a, R> where
R: Unpin,
R: Unpin,
impl<'a, R> !UnwindSafe for Encoder<'a, R>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,