it works~~~

cli-redesign
Avril 4 years ago
parent 8c8265df52
commit e1b1539a57
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -77,7 +77,7 @@ fn find(haystack: &[u8], needle: &[u8]) -> Option<usize> {
#[inline]
fn find_back(haystack: &[u8], needle: &[u8]) -> Option<usize> {
haystack.windows(needle.len()).rev().position(|window| window == needle)
haystack.windows(needle.len()).rev().position(|window| window == needle).and_then(|v| Some(haystack.len() - v))
}
const MARKER_BASE64_BEGIN: &[u8] = b"base64,";
@ -89,10 +89,12 @@ pub(super) fn find_bounds(from: impl AsRef<[u8]>) -> Result<Range<usize>, error:
let from = from.as_ref();
if let Some(start) = find(from, MARKER_BASE64_BEGIN) {
if let Some(end) = find_back(from, MARKER_BASE64_END) {
let start = start + MARKER_BASE64_BEGIN.len();
if let Some(end) = find_back(&from[start..], MARKER_BASE64_END) {//find_back(from, MARKER_BASE64_END) {
let end = end - MARKER_BASE64_END.len();
return Ok(Range {
start,
end,
end: end + start,
});
}
}

@ -25,7 +25,8 @@ where S: AsRef<[u8]>,
let input_bytes = input.as_ref();
let output_bytes = output.as_mut();
Ok(base64::decode_config_slice(input_bytes, base64::STANDARD, output_bytes)?)
//panic!("{:?}", std::str::from_utf8(input_bytes).expect("XXX fatal"));
Ok(base64::decode_config_slice(input_bytes, base64::STANDARD, output_bytes)?) // XXX: This fails
}
/// Calculate the size for a base64 inpue
@ -107,12 +108,6 @@ impl BasedLoli
self.size_decoded
}
/// Attempt to decode to a child container
#[inline]
pub fn decode(&self, loli: &mut Loli) -> Result<usize, error::Error>
{
decode(self, loli)
}
}
impl<'a> LoliBounds<'a>
@ -138,6 +133,15 @@ impl<'a> LoliBounds<'a>
file: file,
})
}
/// Attempt to decode to a child container of our owner
#[inline]
pub fn decode(&self, loli: &mut Loli) -> Result<usize, error::Error>
{
let bytes = self.loli.bytes();
decode(&bytes[self.range.clone()], loli)
}
}
impl AsRef<[u8]> for BasedLoli

@ -19,11 +19,12 @@ pub async fn decode(from: impl AsRef<Path>, to: impl AsRef<Path>, progress: &mut
{
prog_send!(link progress.println("Mapping child"));
let base = loli::BasedLoli::map(from)?;
prog_send!(link progress.println("Calculating bounds"));
let bounds = base.calculate_bounds()?; // If server is returning error code, this will fail.
prog_send!(link progress.println(format!("Decoding {} -> {} bytes", base.as_ref().len(), base.decoded_size())));
prog_send!(link progress.println(format!("Decoding ({:?}) {} -> {} bytes", bounds, base.as_ref().len(), base.decoded_size())));
let mut decoded = bounds.create_child(to)?;
prog_send!(progress.println("Decoding..."));
let sz = base.decode(&mut decoded)?;
let sz = bounds.decode(&mut decoded)?;
prog_send!(link progress.println(format!("Decode complete ({} bytes)", sz)));
Ok(decoded)

Loading…
Cancel
Save