|
1 |
| -use crate::{set_panic_hook, Options}; |
| 1 | +use crate::set_panic_hook; |
2 | 2 | use brotli::enc::encode::{
|
3 | 3 | BrotliEncoderCompressStream, BrotliEncoderCreateInstance, BrotliEncoderDestroyInstance,
|
4 | 4 | BrotliEncoderIsFinished, BrotliEncoderOperation, BrotliEncoderParameter,
|
@@ -38,28 +38,26 @@ impl Drop for CompressStream {
|
38 | 38 | #[wasm_bindgen]
|
39 | 39 | impl CompressStream {
|
40 | 40 | #[wasm_bindgen(constructor)]
|
41 |
| - pub fn new(raw_options: &JsValue) -> Result<CompressStream, JsValue> { |
| 41 | + pub fn new(quality: Option<u32>) -> CompressStream { |
42 | 42 | 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 |
| - }; |
50 | 43 | let alloc = StandardAlloc::default();
|
51 | 44 | 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 { |
58 | 56 | state,
|
59 | 57 | result: BrotliStreamResult::Init as i32,
|
60 | 58 | total_out: 0,
|
61 | 59 | last_input_offset: 0,
|
62 |
| - }) |
| 60 | + } |
63 | 61 | }
|
64 | 62 |
|
65 | 63 | pub fn compress(
|
|
0 commit comments