Skip to content

Commit c09c932

Browse files
committed
implement init_alone
1 parent 9bd7f18 commit c09c932

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

stdlib/src/lzma.rs

+23-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ mod _lzma {
3939
use rustpython_vm::types::Constructor;
4040
use rustpython_vm::{PyObjectRef, PyPayload, PyResult, VirtualMachine};
4141
use std::fmt;
42-
use xz2::stream::{Action, Check, Error, Filters, Status, Stream};
42+
use xz2::stream::{Action, Check, Error, Filters, LzmaOptions, Status, Stream};
4343

4444
#[cfg(windows)]
4545
type EnumVal = i32;
@@ -322,6 +322,26 @@ mod _lzma {
322322
.map_err(|_| new_lzma_error("Failed to initialize encoder", vm))?)
323323
}
324324
}
325+
326+
fn init_alone(
327+
preset: u32,
328+
filter_specs: Option<Vec<PyObjectRef>>,
329+
vm: &VirtualMachine,
330+
) -> PyResult<Stream> {
331+
if let Some(filter_specs) = filter_specs {
332+
Err(new_lzma_error(
333+
"TODO: RUSTPYTHON: LZMA: Alone filter specs",
334+
vm,
335+
))
336+
} else {
337+
let options = LzmaOptions::new_preset(preset)
338+
.map_err(|_| new_lzma_error("Failed to initialize encoder", vm))?;
339+
let stream = Stream::new_lzma_encoder(&options).map_err(|_| {
340+
new_lzma_error("Failed to initialize encoder", vm)
341+
})?;
342+
Ok(stream)
343+
}
344+
}
325345
}
326346

327347
#[derive(FromArgs)]
@@ -365,7 +385,8 @@ mod _lzma {
365385
}
366386
let stream = match args.format {
367387
FORMAT_XZ => Self::init_xz(args.check, preset, args.filters, vm)?,
368-
// TODO: ALONE AND RAW
388+
FORMAT_ALONE => Self::init_alone(preset, args.filters, vm)?,
389+
// TODO: RAW
369390
_ => return Err(new_lzma_error("Invalid format", vm)),
370391
};
371392
Ok(Self {

0 commit comments

Comments
 (0)