[xmly] chore: rename streams
This commit is contained in:
parent
4ca1bfe2c8
commit
6a60dec89b
@ -44,9 +44,8 @@ impl ArgsXimalaya {
|
|||||||
_ => bail!("ext not found"),
|
_ => bail!("ext not found"),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
let mut read_stream = BufReader::with_capacity(cli.buffer_size, File::open(&self.input)?);
|
let mut reader = BufReader::with_capacity(cli.buffer_size, File::open(&self.input)?);
|
||||||
let mut write_stream =
|
let mut writer = BufWriter::with_capacity(cli.buffer_size, File::create(&self.output)?);
|
||||||
BufWriter::with_capacity(cli.buffer_size, File::create(&self.output)?);
|
|
||||||
|
|
||||||
match file_type {
|
match file_type {
|
||||||
XimalayaType::X2M | XimalayaType::X3M => {
|
XimalayaType::X2M | XimalayaType::X3M => {
|
||||||
@ -56,36 +55,36 @@ impl ArgsXimalaya {
|
|||||||
_ => bail!("this should not happen"),
|
_ => bail!("this should not happen"),
|
||||||
};
|
};
|
||||||
let mut header = [0u8; 0x400];
|
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);
|
umc_xmly::android::decrypt_android(android_type, &mut header);
|
||||||
write_stream.write_all(&header)?;
|
writer.write_all(&header)?;
|
||||||
io::copy(&mut read_stream, &mut write_stream)?;
|
io::copy(&mut reader, &mut writer)?;
|
||||||
}
|
}
|
||||||
XimalayaType::XM => {
|
XimalayaType::XM => {
|
||||||
let mut header = vec![0u8; 1024];
|
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) {
|
let xm_file = match umc_xmly::pc::Header::from_buffer(&header) {
|
||||||
Ok(hdr) => hdr,
|
Ok(hdr) => hdr,
|
||||||
Err(umc_xmly::XmlyError::MetadataTooSmall(n)) => {
|
Err(umc_xmly::XmlyError::MetadataTooSmall(n)) => {
|
||||||
let old_size = header.len();
|
let old_size = header.len();
|
||||||
header.resize(n, 0);
|
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)?
|
umc_xmly::pc::Header::from_buffer(&header)?
|
||||||
}
|
}
|
||||||
Err(err) => bail!("failed to parse file: {err}"),
|
Err(err) => bail!("failed to parse file: {err}"),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Copy header
|
// 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
|
// 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];
|
let mut header = vec![0u8; xm_file.encrypted_header_size];
|
||||||
read_stream.read_exact(&mut header[..])?;
|
reader.read_exact(&mut header[..])?;
|
||||||
write_stream.write_all(xm_file.decrypt(&mut header[..])?)?;
|
writer.write_all(xm_file.decrypt(&mut header[..])?)?;
|
||||||
|
|
||||||
// Copy rest of the file
|
// Copy rest of the file
|
||||||
io::copy(&mut read_stream, &mut write_stream)?;
|
io::copy(&mut reader, &mut writer)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user