summaryrefslogtreecommitdiffstats
path: root/vendor/xz2/src/stream.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:42 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:42 +0000
commit837b550238aa671a591ccf282dddeab29cadb206 (patch)
tree914b6b8862bace72bd3245ca184d374b08d8a672 /vendor/xz2/src/stream.rs
parentAdding debian version 1.70.0+dfsg2-1. (diff)
downloadrustc-837b550238aa671a591ccf282dddeab29cadb206.tar.xz
rustc-837b550238aa671a591ccf282dddeab29cadb206.zip
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/xz2/src/stream.rs')
-rw-r--r--vendor/xz2/src/stream.rs115
1 files changed, 65 insertions, 50 deletions
diff --git a/vendor/xz2/src/stream.rs b/vendor/xz2/src/stream.rs
index b005f26d8..88681f1fb 100644
--- a/vendor/xz2/src/stream.rs
+++ b/vendor/xz2/src/stream.rs
@@ -52,13 +52,13 @@ pub struct Filters {
/// the amount of input will make `process` return `Error::Program`.
#[derive(Copy, Clone)]
pub enum Action {
- /// Continue processing
- ///
+ /// Continue processing
+ ///
/// When encoding, encode as much input as possible. Some internal buffering
/// will probably be done (depends on the filter chain in use), which causes
/// latency: the input used won't usually be decodeable from the output of
/// the same `process` call.
- ///
+ ///
/// When decoding, decode as much input as possible and produce as much
/// output as possible.
Run = lzma_sys::LZMA_RUN as isize,
@@ -278,9 +278,11 @@ impl Stream {
pub fn new_easy_encoder(preset: u32, check: Check) -> Result<Stream, Error> {
unsafe {
let mut init = Stream { raw: mem::zeroed() };
- cvt(lzma_sys::lzma_easy_encoder(&mut init.raw,
- preset,
- check as lzma_sys::lzma_check))?;
+ cvt(lzma_sys::lzma_easy_encoder(
+ &mut init.raw,
+ preset,
+ check as lzma_sys::lzma_check,
+ ))?;
Ok(init)
}
}
@@ -310,13 +312,14 @@ impl Stream {
///
/// This function is similar to `new_easy_encoder` but a custom filter chain
/// is specified.
- pub fn new_stream_encoder(filters: &Filters,
- check: Check) -> Result<Stream, Error> {
+ pub fn new_stream_encoder(filters: &Filters, check: Check) -> Result<Stream, Error> {
unsafe {
let mut init = Stream { raw: mem::zeroed() };
- cvt(lzma_sys::lzma_stream_encoder(&mut init.raw,
- filters.inner.as_ptr(),
- check as lzma_sys::lzma_check))?;
+ cvt(lzma_sys::lzma_stream_encoder(
+ &mut init.raw,
+ filters.inner.as_ptr(),
+ check as lzma_sys::lzma_check,
+ ))?;
Ok(init)
}
}
@@ -326,13 +329,14 @@ impl Stream {
/// The maximum memory usage can be specified along with flags such as
/// `TELL_ANY_CHECK`, `TELL_NO_CHECK`, `TELL_UNSUPPORTED_CHECK`,
/// `TELL_IGNORE_CHECK`, or `CONCATENATED`.
- pub fn new_stream_decoder(memlimit: u64,
- flags: u32) -> Result<Stream, Error> {
+ pub fn new_stream_decoder(memlimit: u64, flags: u32) -> Result<Stream, Error> {
unsafe {
let mut init = Stream { raw: mem::zeroed() };
- cvt(lzma_sys::lzma_stream_decoder(&mut init.raw,
- memlimit,
- flags))?;
+ cvt(lzma_sys::lzma_stream_decoder(
+ &mut init.raw,
+ memlimit,
+ flags,
+ ))?;
Ok(init)
}
}
@@ -343,8 +347,7 @@ impl Stream {
pub fn new_lzma_decoder(memlimit: u64) -> Result<Stream, Error> {
unsafe {
let mut init = Stream { raw: mem::zeroed() };
- cvt(lzma_sys::lzma_alone_decoder(&mut init.raw,
- memlimit))?;
+ cvt(lzma_sys::lzma_alone_decoder(&mut init.raw, memlimit))?;
Ok(init)
}
}
@@ -354,9 +357,7 @@ impl Stream {
pub fn new_auto_decoder(memlimit: u64, flags: u32) -> Result<Stream, Error> {
unsafe {
let mut init = Stream { raw: mem::zeroed() };
- cvt(lzma_sys::lzma_auto_decoder(&mut init.raw,
- memlimit,
- flags))?;
+ cvt(lzma_sys::lzma_auto_decoder(&mut init.raw, memlimit, flags))?;
Ok(init)
}
}
@@ -366,18 +367,18 @@ impl Stream {
/// This will perform the appropriate encoding or decoding operation
/// depending on the kind of underlying stream. Documentation for the
/// various `action` arguments can be found on the respective variants.
- pub fn process(&mut self,
- input: &[u8],
- output: &mut [u8],
- action: Action) -> Result<Status, Error> {
+ pub fn process(
+ &mut self,
+ input: &[u8],
+ output: &mut [u8],
+ action: Action,
+ ) -> Result<Status, Error> {
self.raw.next_in = input.as_ptr();
self.raw.avail_in = input.len();
self.raw.next_out = output.as_mut_ptr();
self.raw.avail_out = output.len();
let action = action as lzma_sys::lzma_action;
- unsafe {
- cvt(lzma_sys::lzma_code(&mut self.raw, action))
- }
+ unsafe { cvt(lzma_sys::lzma_code(&mut self.raw, action)) }
}
/// Performs the same data as `process`, but places output data in a `Vec`.
@@ -385,10 +386,12 @@ impl Stream {
/// This function will use the extra capacity of `output` as a destination
/// for bytes to be placed. The length of `output` will automatically get
/// updated after the operation has completed.
- pub fn process_vec(&mut self,
- input: &[u8],
- output: &mut Vec<u8>,
- action: Action) -> Result<Status, Error> {
+ pub fn process_vec(
+ &mut self,
+ input: &[u8],
+ output: &mut Vec<u8>,
+ action: Action,
+ ) -> Result<Status, Error> {
let cap = output.capacity();
let len = output.len();
@@ -400,7 +403,7 @@ impl Stream {
self.process(input, out, action)
};
output.set_len((self.total_out() - before) as usize + len);
- return ret
+ return ret;
}
}
@@ -426,8 +429,7 @@ impl Stream {
/// This can return `Error::MemLimit` if the new limit is too small or
/// `Error::Program` if this stream doesn't take a memory limit.
pub fn set_memlimit(&mut self, limit: u64) -> Result<(), Error> {
- cvt(unsafe { lzma_sys::lzma_memlimit_set(&mut self.raw, limit) })
- .map(|_| ())
+ cvt(unsafe { lzma_sys::lzma_memlimit_set(&mut self.raw, limit) }).map(|_| ())
}
}
@@ -572,9 +574,7 @@ impl LzmaOptions {
impl Check {
/// Test if this check is supported in this build of liblzma.
pub fn is_supported(&self) -> bool {
- let ret = unsafe {
- lzma_sys::lzma_check_is_supported(*self as lzma_sys::lzma_check)
- };
+ let ret = unsafe { lzma_sys::lzma_check_is_supported(*self as lzma_sys::lzma_check) };
ret != 0
}
}
@@ -582,9 +582,7 @@ impl Check {
impl MatchFinder {
/// Test if this match finder is supported in this build of liblzma.
pub fn is_supported(&self) -> bool {
- let ret = unsafe {
- lzma_sys::lzma_mf_is_supported(*self as lzma_sys::lzma_match_finder)
- };
+ let ret = unsafe { lzma_sys::lzma_mf_is_supported(*self as lzma_sys::lzma_match_finder) };
ret != 0
}
}
@@ -700,7 +698,7 @@ impl MtStreamBuilder {
filters: None,
};
init.raw.threads = 1;
- return init
+ return init;
}
}
@@ -792,8 +790,7 @@ impl MtStreamBuilder {
pub fn encoder(&self) -> Result<Stream, Error> {
unsafe {
let mut init = Stream { raw: mem::zeroed() };
- cvt(lzma_sys::lzma_stream_encoder_mt(&mut init.raw,
- &self.raw))?;
+ cvt(lzma_sys::lzma_stream_encoder_mt(&mut init.raw, &self.raw))?;
Ok(init)
}
}
@@ -819,17 +816,36 @@ fn cvt(rc: lzma_sys::lzma_ret) -> Result<Status, Error> {
impl From<Error> for io::Error {
fn from(e: Error) -> io::Error {
- io::Error::new(io::ErrorKind::Other, e)
+ let kind = match e {
+ Error::Data => std::io::ErrorKind::InvalidData,
+ Error::Options => std::io::ErrorKind::InvalidInput,
+ Error::Format => std::io::ErrorKind::InvalidData,
+ Error::MemLimit => std::io::ErrorKind::Other,
+ Error::Mem => std::io::ErrorKind::Other,
+ Error::Program => std::io::ErrorKind::Other,
+ Error::NoCheck => std::io::ErrorKind::InvalidInput,
+ Error::UnsupportedCheck => std::io::ErrorKind::Other,
+ };
+
+ io::Error::new(kind, e)
}
}
-impl error::Error for Error {
- fn description(&self) -> &str { "lzma data error" }
-}
+impl error::Error for Error {}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- error::Error::description(self).fmt(f)
+ match self {
+ Error::Data => "lzma data error",
+ Error::Options => "invalid options",
+ Error::Format => "stream/file format not recognized",
+ Error::MemLimit => "memory limit reached",
+ Error::Mem => "can't allocate memory",
+ Error::Program => "liblzma internal error",
+ Error::NoCheck => "no integrity check was available",
+ Error::UnsupportedCheck => "liblzma not built with check support",
+ }
+ .fmt(f)
}
}
@@ -840,4 +856,3 @@ impl Drop for Stream {
}
}
}
-