Compare commits

..

2 Commits

Author SHA1 Message Date
15547f237b [wasm] chore: bump version to alpha.10 2024-09-15 00:41:12 +01:00
e7602cee4c [wasm] feat: return -1 when file is not NCM 2024-09-15 00:40:42 +01:00
2 changed files with 7 additions and 4 deletions

View File

@ -19,22 +19,25 @@ impl JsNCMFile {
/// Open NCM file. /// Open NCM file.
/// If everything is ok, return `0`. /// 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 /// # Arguments
/// ///
/// * `header`: Header bytes of NCM file. /// * `header`: Header bytes of NCM file.
/// ///
/// returns: Result<usize, JsError> /// returns: Result<i32, JsError>
/// ///
/// If it needs more bytes, the new header size will be returned. /// If it needs more bytes, the new header size will be returned.
/// If the header was large enough, it will return 0. /// If the header was large enough, it will return 0.
pub fn open(&mut self, header: &[u8]) -> Result<usize, JsError> { pub fn open(&mut self, header: &[u8]) -> Result<i32, JsError> {
match NCMFile::new(header) { match NCMFile::new(header) {
Ok(ncm) => { Ok(ncm) => {
self.ncm = Some(ncm); self.ncm = Some(ncm);
Ok(0) 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())), Err(err) => Err(JsError::new(err.to_string().as_str())),
} }
} }

View File

@ -1,6 +1,6 @@
{ {
"name": "@unlock-music/crypto", "name": "@unlock-music/crypto",
"version": "0.0.0-alpha.9", "version": "0.0.0-alpha.10",
"description": "Project Unlock Music: 加解密支持库", "description": "Project Unlock Music: 加解密支持库",
"scripts": { "scripts": {
"build": "node build.js", "build": "node build.js",