From e7602cee4c3e16c17c4acbb1944742c813c10859 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B2=81=E6=A0=91=E4=BA=BA?= Date: Sun, 15 Sep 2024 00:40:42 +0100 Subject: [PATCH] [wasm] feat: return -1 when file is not NCM --- um_wasm/src/exports/ncm.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/um_wasm/src/exports/ncm.rs b/um_wasm/src/exports/ncm.rs index 4e41773..5bc49ac 100644 --- a/um_wasm/src/exports/ncm.rs +++ b/um_wasm/src/exports/ncm.rs @@ -19,22 +19,25 @@ impl JsNCMFile { /// Open NCM file. /// If everything is ok, return `0`. + /// If it needs more header bytes, return positive integer. + /// If it was not a valid NCM file, return -1. /// /// # Arguments /// /// * `header`: Header bytes of NCM file. /// - /// returns: Result + /// returns: Result /// /// If it needs more bytes, the new header size will be returned. /// If the header was large enough, it will return 0. - pub fn open(&mut self, header: &[u8]) -> Result { + pub fn open(&mut self, header: &[u8]) -> Result { match NCMFile::new(header) { Ok(ncm) => { self.ncm = Some(ncm); Ok(0) } - Err(NetEaseCryptoError::HeaderTooSmall(n)) => Ok(n), + Err(NetEaseCryptoError::HeaderTooSmall(n)) => Ok(n as i32), + Err(NetEaseCryptoError::NotNCMFile) => Ok(-1), Err(err) => Err(JsError::new(err.to_string().as_str())), } }