Struct EncodeOptions

Source
pub struct EncodeOptions { /* private fields */ }
Expand description

Options for encoding. The entry point for encoding a file (part) to a file or (TCP) stream.

Implementations§

Source§

impl EncodeOptions

Source

pub fn new() -> EncodeOptions

Constructs a new EncodeOptions with defaults, see Default impl.

Source

pub fn line_length(self, line_length: u8) -> EncodeOptions

Sets the maximum line length.

Source

pub fn parts(self, parts: u32) -> EncodeOptions

Sets the number of parts (default=1). When the number of parts is 1, no ‘=ypart’ line will be written in the ouput.

Source

pub fn part(self, part: u32) -> EncodeOptions

Sets the part number. Only used when parts > 1. The part number count starts at 1.

Source

pub fn begin(self, begin: u64) -> EncodeOptions

Sets the begin (which is the file offset + 1). Only used when parts > 1. The size of the part is end - begin + 1.

Source

pub fn end(self, end: u64) -> EncodeOptions

Sets the end. Only used when parts > 1. The size of the part is end - begin + 1. end should be larger than begin, otherwise an overflow error occurrs.

Source

pub fn encode_file<P, W>( &self, input_path: P, output: W, ) -> Result<(), EncodeError>
where P: AsRef<Path>, W: Write,

Encodes the input file and writes it to the writer. For multi-part encoding, only one part is encoded. In case of multipart, the part number, begin and end offset need to be specified in the EncodeOptions. When directly encoding to an NNTP stream, the caller needs to take care of the message header and end of multi-line block (".\r\n").

§Example
let encode_options = yenc::EncodeOptions::default()
                                        .parts(2)
                                        .part(1)
                                        .begin(1)
                                        .end(38400);
let mut output_file = std::fs::File::create("test1.bin.yenc.001").unwrap();
encode_options.encode_file("test1.bin", &mut output_file).unwrap();
§Errors
  • when the output file already exists
Source

pub fn check_options(&self) -> Result<(), EncodeError>

Checks the options. Returns Ok(()) if all options are ok.

§Return
  • EncodeError::PartNumberMissing
  • EncodeError::PartBeginOffsetMissing
  • EncodeError::PartEndOffsetMissing
  • EncodeError::PartOffsetsInvalidRange
Source

pub fn encode_stream<R, W>( &self, input: R, output: W, length: u64, input_filename: &str, ) -> Result<(), EncodeError>
where R: Read + Seek, W: Write,

Encodes the date from input from stream and writes the encoded data to the output stream. The input stream does not need to be a file, therefore, size and input_filename must be specified. The input_filename ends up as the filename in the yenc header.

Trait Implementations§

Source§

impl Debug for EncodeOptions

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for EncodeOptions

Source§

fn default() -> Self

Constructs a new EncodeOptions instance, with the following defaults: line_length = 128. parts = 1, part = begin = end = 0

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.