Avoid an intermediary buffer in LZMA decoder
This commit is contained in:
parent
e9b13121cc
commit
2e679997b0
1 changed files with 5 additions and 9 deletions
|
@ -1,8 +1,6 @@
|
|||
use lzma_rs::decompress::{Options, Stream, UnpackedSize};
|
||||
use std::collections::VecDeque;
|
||||
use std::io::{Read, Result, Write};
|
||||
|
||||
const COMPRESSED_BYTES_TO_BUFFER: usize = 4096;
|
||||
use std::io::{BufRead, Read, Result, Write};
|
||||
|
||||
const OPTIONS: Options = Options {
|
||||
unpacked_size: UnpackedSize::ReadFromHeader,
|
||||
|
@ -29,17 +27,15 @@ impl<R: Read> LzmaDecoder<R> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<R: Read> Read for LzmaDecoder<R> {
|
||||
impl<R: BufRead> Read for LzmaDecoder<R> {
|
||||
fn read(&mut self, buf: &mut [u8]) -> Result<usize> {
|
||||
let mut bytes_read = self.stream.get_output_mut().unwrap().read(buf)?;
|
||||
while bytes_read < buf.len() {
|
||||
let mut next_compressed = [0u8; COMPRESSED_BYTES_TO_BUFFER];
|
||||
let compressed_bytes_read = self.compressed_reader.read(&mut next_compressed)?;
|
||||
if compressed_bytes_read == 0 {
|
||||
let compressed_bytes = self.compressed_reader.fill_buf()?;
|
||||
if compressed_bytes.is_empty() {
|
||||
break;
|
||||
}
|
||||
self.stream
|
||||
.write_all(&next_compressed[..compressed_bytes_read])?;
|
||||
self.stream.write_all(compressed_bytes)?;
|
||||
bytes_read += self
|
||||
.stream
|
||||
.get_output_mut()
|
||||
|
|
Loading…
Add table
Reference in a new issue