Comments (10)
Would #17 (or a variant of it) work for this use case?
from lzma-rs.
Do you have a reference to the code or documentation, and example files to test this? Otherwise it will be hard to add support for this use case. Feel free to send a pull request as well!
from lzma-rs.
Yes, see how it is done https://github.com/XVilka/ocaml-lzma_7z/blob/master/lzma.ml#L387
One of the cases it was used - very old 7Zip SDK, which was used in the modified CramFS version that used LZMA:
Note how it is used 32bit ints for outsize:
- https://github.com/digiampietro/lzma-uncramfs/blob/master/lzma-rg/SRC/7zip/Compress/LZMA_C/LzmaDecode.c
- https://github.com/digiampietro/lzma-uncramfs/blob/master/lzma-rg/SRC/7zip/Compress/LZMA_C/decode.c#L87
from lzma-rs.
Yes, ability to form the header manually is good enough, thanks!
from lzma-rs.
The implementation in #17 only supports a 64-bit or 0-bit field for the unpacked size though. So I assume it wouldn't work for a 32-bit unpacked size out-of-the-box.
from lzma-rs.
@gendx someone also needs this feature it seems, not only me: https://users.rust-lang.org/t/extract-lzma-file/24793/5
from lzma-rs.
@gendx someone is also needs this feature it seems, not only me: https://users.rust-lang.org/t/extract-lzma-file/24793/5
Thanks for the pointer. I don't have a lot of time for implementing it at the moment, nor files from the old SDK to test with.
But feel free to send a pull request, I'll be happy to take a look!
from lzma-rs.
If the unpacked_size
is known beforehand, #74 should cover most of this use case, except for reading the 13-byte header. You would have to read the header manually then construct the decoder with the params.
from lzma-rs.
Will this do ?
`impl LzmaParams {
// Other methods omitted for brevity
/// Read LZMA parameters from the LZMA stream header.
pub fn read_header<R>(input: &mut R, options: &Options) -> error::Result<LzmaParams>
where
R: io::BufRead,
{
// Properties
let props = input.read_u8().map_err(error::Error::HeaderTooShort)?;
let mut pb = props as u32;
if pb == 0xFF {
return Err(error::Error::InvalidLzmaProperties);
}
pb = pb % 9;
let mut lp = (props / 9) as u32;
if lp == 0xFF {
return Err(error::Error::InvalidLzmaProperties);
}
lp = lp % 5;
let mut lc = (props / (9 * 5)) as u32;
if lc == 0xFF {
return Err(error::Error::InvalidLzmaProperties);
}
lc = lc % 9;
let properties = LzmaProperties { lc, lp, pb };
// Dictionary size
let mut dict_size = [0u8; 4];
input
.read_exact(&mut dict_size)
.map_err(error::Error::HeaderTooShort)?;
let dict_size = u32::from_le_bytes(dict_size) as usize;
// Unpacked size
let mut unpacked_size = [0u8; 8];
input
.read_exact(&mut unpacked_size[0..4])
.map_err(error::Error::HeaderTooShort)?;
let unpacked_size = u32::from_le_bytes(unpacked_size[0..4]) as usize;
Ok(Self {
properties,
dict_size,
unpacked_size,
})
}
}
`
from lzma-rs.
Tests will look as follows
`
#[test]
fn test_lzma_params_read_header() {
// Test reading LZMA params from a valid stream header
let mut input = Cursor::new(b"\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00");
let options = Options::default();
let params = LzmaParams::read_header(&mut input, &options);
assert!(params.is_ok());
let params = params.unwrap();
assert_eq!(params.properties.lc, 0);
assert_eq!(params.properties.lp, 0);
assert_eq!(params.properties.pb, 1);
assert_eq!(params.dict_size, 1);
assert_eq!(params.unpacked_size, None);
// Test reading LZMA params from a stream header with unpacked size
let mut input = Cursor::new(b"\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x64");
let options = Options::default();
let params = LzmaParams::read_header(&mut input, &options);
assert!(params.is_ok());
let params = params.unwrap();
assert_eq!(params.properties.lc, 0);
assert_eq!(params.properties.lp, 0);
assert_eq!(params.properties.pb, 1);
assert_eq!(params.dict_size, 1);
assert_eq!(params.unpacked_size, Some(100));
// Test reading LZMA params from a stream header with invalid properties
let mut input = Cursor::new(b"\xFF\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00");
let options = Options::default();
let params = LzmaParams::read_header(&mut input, &options);
assert!(params.is_err());
// Test reading LZMA params from a stream header with too few bytes
let mut input = Cursor::new(b"\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00");
let options = Options::default();
let params = LzmaParams::read_header(&mut input, &options);
assert!(params.is_err());
}
`
from lzma-rs.
Related Issues (20)
- Publish some benchmarks on `README.md`
- add `xz_decompress_with_options` API
- Panic on decoding xz file with sha256 checksum
- Test against the XZ test suite HOT 4
- Behavior mismatches between liblzma and lzma-rs HOT 1
- Provide features to import parts of the crate HOT 3
- Enable no_std support HOT 4
- Add configurable memory limit
- Support multi-stream files
- .lz (lzip) HOT 2
- Expose decoder/encoder primitives as public HOT 4
- Add unit tests
- Report code coverage
- Reach 100% coverage.
- Problems when porting lzma code Java -> Rust HOT 1
- New release
- XZ: Unknown filter id 7 HOT 2
- API Suggestion: Add encoder and decoder structs
- Extraction fails with `Unknown filter id 8` HOT 2
- lzma2_compress and zx_compress do not compress input HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lzma-rs.