[wasm] feat: return -1 when file is not NCM

This commit is contained in:
鲁树人 2024-09-15 00:40:42 +01:00
parent e6e88913d9
commit e7602cee4c

View File

@ -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<usize, JsError>
/// returns: Result<i32, JsError>
///
/// 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<usize, JsError> {
pub fn open(&mut self, header: &[u8]) -> Result<i32, JsError> {
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())),
}
}