Properly flush stdout while uploading

This commit is contained in:
Emi Simpson 2022-08-13 21:41:22 -04:00
parent 0530bf42f6
commit 4dc5ffa936
Signed by: Emi
GPG key ID: A12F2C2FFDC3D847

View file

@ -76,6 +76,7 @@ fn create(server: &str, args: CreateArgs) {
};
let index_url = files.into_iter()
.inspect(|(path, _)| print!("\x1b[36m{}\x1b[0m\n\x1b[37m├─\x1b[0m Reading... ", path.display()))
.inspect(|_| drop(stdout().flush()))
.map(|(path, mut file)|
(|| {
let mut buff = Vec::with_capacity(file.metadata()?.len() as usize);
@ -84,12 +85,14 @@ fn create(server: &str, args: CreateArgs) {
})().map_err(|e| AviaryError::StreamReadError(path.to_owned(), e))
)
.inspect(|r| if r.is_ok() { print!("\x1b[32mDone!\n\x1b[37m├─\x1b[0m Thumbnailing... ") })
.inspect(|_| drop(stdout().flush()))
.map(|r| r.and_then(|(path, raw_dat)| {
let (thumbnail, blurhash) = thumbnailing::thumbnail(&raw_dat)
.map_err(|_| AviaryError::ImageFormatError(path.to_owned()))?;
Ok((raw_dat, thumbnail, blurhash))
}))
.inspect(|r| if r.is_ok() { print!("\x1b[32mDone!\n\x1b[37m├─\x1b[0m Encrypting... ")})
.inspect(|_| drop(stdout().flush()))
.map_ok(|(raw_dat, thumbnail, blurhash)| {
let key = crypto::make_key();
(
@ -100,6 +103,7 @@ fn create(server: &str, args: CreateArgs) {
)
})
.inspect(|r| if r.is_ok() { print!("\x1b[32mDone!\n\x1b[37m└─\x1b[0m Uploading... ")})
.inspect(|_| drop(stdout().flush()))
.map(|r| r.and_then(|(key, full_img, thumb, blurhash)|
upload::put_data(&agent, &*full_server, &thumb)
.and_then(|thumb_url|