Skip to content

Commit 49dba8c

Browse files
committed
Change way to pass options for compressing
No method to disable ts completely for a class, so change not to use custom Options
1 parent 634562a commit 49dba8c

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

src/stream.rs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{set_panic_hook, Options};
1+
use crate::set_panic_hook;
22
use brotli::enc::encode::{
33
BrotliEncoderCompressStream, BrotliEncoderCreateInstance, BrotliEncoderDestroyInstance,
44
BrotliEncoderIsFinished, BrotliEncoderOperation, BrotliEncoderParameter,
@@ -38,28 +38,26 @@ impl Drop for CompressStream {
3838
#[wasm_bindgen]
3939
impl CompressStream {
4040
#[wasm_bindgen(constructor)]
41-
pub fn new(raw_options: &JsValue) -> Result<CompressStream, JsValue> {
41+
pub fn new(quality: Option<u32>) -> CompressStream {
4242
set_panic_hook();
43-
let options: Options = if raw_options.is_undefined() {
44-
serde_json::from_str("{}").unwrap()
45-
} else if raw_options.is_object() {
46-
raw_options.into_serde().unwrap()
47-
} else {
48-
return Err(JsValue::from_str("Options is not an object"));
49-
};
5043
let alloc = StandardAlloc::default();
5144
let mut state = BrotliEncoderCreateInstance(alloc);
52-
BrotliEncoderSetParameter(
53-
&mut state,
54-
BrotliEncoderParameter::BROTLI_PARAM_QUALITY,
55-
options.quality as u32,
56-
);
57-
Ok(Self {
45+
match quality {
46+
None => (),
47+
Some(quality) => {
48+
BrotliEncoderSetParameter(
49+
&mut state,
50+
BrotliEncoderParameter::BROTLI_PARAM_QUALITY,
51+
quality,
52+
);
53+
}
54+
}
55+
Self {
5856
state,
5957
result: BrotliStreamResult::Init as i32,
6058
total_out: 0,
6159
last_input_offset: 0,
62-
})
60+
}
6361
}
6462

6563
pub fn compress(

0 commit comments

Comments
 (0)