From 6a60dec89b8f82becb6138b6cea068ce9e437abc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B2=81=E6=A0=91=E4=BA=BA?= Date: Wed, 18 Sep 2024 23:00:51 +0100 Subject: [PATCH] [xmly] chore: rename streams --- um_cli/src/cmd/xmly.rs | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/um_cli/src/cmd/xmly.rs b/um_cli/src/cmd/xmly.rs index 02286ed..1f10b8a 100644 --- a/um_cli/src/cmd/xmly.rs +++ b/um_cli/src/cmd/xmly.rs @@ -44,9 +44,8 @@ impl ArgsXimalaya { _ => bail!("ext not found"), }, }; - let mut read_stream = BufReader::with_capacity(cli.buffer_size, File::open(&self.input)?); - let mut write_stream = - BufWriter::with_capacity(cli.buffer_size, File::create(&self.output)?); + let mut reader = BufReader::with_capacity(cli.buffer_size, File::open(&self.input)?); + let mut writer = BufWriter::with_capacity(cli.buffer_size, File::create(&self.output)?); match file_type { XimalayaType::X2M | XimalayaType::X3M => { @@ -56,36 +55,36 @@ impl ArgsXimalaya { _ => bail!("this should not happen"), }; let mut header = [0u8; 0x400]; - read_stream.read_exact(&mut header)?; + reader.read_exact(&mut header)?; umc_xmly::android::decrypt_android(android_type, &mut header); - write_stream.write_all(&header)?; - io::copy(&mut read_stream, &mut write_stream)?; + writer.write_all(&header)?; + io::copy(&mut reader, &mut writer)?; } XimalayaType::XM => { let mut header = vec![0u8; 1024]; - read_stream.read_exact(&mut header)?; + reader.read_exact(&mut header)?; let xm_file = match umc_xmly::pc::Header::from_buffer(&header) { Ok(hdr) => hdr, Err(umc_xmly::XmlyError::MetadataTooSmall(n)) => { let old_size = header.len(); header.resize(n, 0); - read_stream.read_exact(&mut header[old_size..])?; + reader.read_exact(&mut header[old_size..])?; umc_xmly::pc::Header::from_buffer(&header)? } Err(err) => bail!("failed to parse file: {err}"), }; // Copy header - write_stream.write_all(xm_file.copy_m4a_header().as_slice())?; + writer.write_all(xm_file.copy_m4a_header().as_slice())?; // Process encrypted data - read_stream.seek(SeekFrom::Start(xm_file.data_start_offset as u64))?; + reader.seek(SeekFrom::Start(xm_file.data_start_offset as u64))?; let mut header = vec![0u8; xm_file.encrypted_header_size]; - read_stream.read_exact(&mut header[..])?; - write_stream.write_all(xm_file.decrypt(&mut header[..])?)?; + reader.read_exact(&mut header[..])?; + writer.write_all(xm_file.decrypt(&mut header[..])?)?; // Copy rest of the file - io::copy(&mut read_stream, &mut write_stream)?; + io::copy(&mut reader, &mut writer)?; } }