summaryrefslogtreecommitdiffstats
path: root/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/lib.rs b/src/lib.rs
index a6c16d9..af2f994 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -53,6 +53,13 @@ impl Server {
}
}
+/// Decodes base64 as output by the `base64` utility. Properly handles
+/// 76-column base64.
+fn decode_base64(s: &'static str) -> Result<Vec<u8>, base64::DecodeError> {
+ // cba to avoid allocation
+ base64::decode(s.split('\n').collect::<String>())
+}
+
/// Spawns a webserver to serve the given archive.
///
/// The archive is an .a (ar) file, in a format that can be parsed by the ar
@@ -153,8 +160,16 @@ pub fn serve(archive: &'static str) -> Server {
current = Some(Archive::new(inner));
} else if kind == ".b" {
// base64
- let inner = base64::decode(inner.into_inner());
- let inner = Cursor::new(inner.unwrap());
+ let inner = decode_base64(inner.into_inner());
+ let inner = match inner {
+ Ok(inner) => inner,
+ Err(e) => {
+ eprintln!("{}", e);
+ break
+ }
+ };
+ let size = inner.len();
+ let inner = Cursor::new(inner);
response = Response::new(
200.into(),
vec![],