we're zipping baby!!!

This commit is contained in:
Zynh0722 2023-04-09 00:03:05 -07:00
parent e8f7edb117
commit 807334f29b
2 changed files with 20 additions and 7 deletions

1
.gitignore vendored
View file

@ -1,2 +1,3 @@
/target /target
.DS_Store .DS_Store
/.cache

View file

@ -1,7 +1,7 @@
use std::io;
use std::net::SocketAddr; use std::net::SocketAddr;
use std::path::{Component, Path}; use std::path::{Component, Path};
use std::sync::Arc; use std::sync::{Arc, Mutex};
use std::io;
use axum::body::Bytes; use axum::body::Bytes;
use axum::http::StatusCode; use axum::http::StatusCode;
@ -19,7 +19,6 @@ use rand::rngs::SmallRng;
use rand::SeedableRng; use rand::SeedableRng;
use tokio::fs::File; use tokio::fs::File;
use tokio::io::BufWriter; use tokio::io::BufWriter;
use tokio::sync::Mutex;
use tokio::task::{spawn_blocking, JoinHandle}; use tokio::task::{spawn_blocking, JoinHandle};
use tokio_util::io::StreamReader; use tokio_util::io::StreamReader;
use tower_http::{limit::RequestBodyLimitLayer, services::ServeDir, trace::TraceLayer}; use tower_http::{limit::RequestBodyLimitLayer, services::ServeDir, trace::TraceLayer};
@ -165,9 +164,9 @@ where
let path = entry.path(); let path = entry.path();
// This feels terribly wrong // This feels terribly wrong
spawn_blocking(|| async move { spawn_blocking(move || {
let mut file = std::fs::File::open(path).unwrap(); let mut file = std::fs::File::open(path).unwrap();
let mut writer = writer.lock().await; let mut writer = writer.lock().unwrap();
let options = zip::write::FileOptions::default() let options = zip::write::FileOptions::default()
.compression_method(zip::CompressionMethod::DEFLATE); .compression_method(zip::CompressionMethod::DEFLATE);
@ -178,9 +177,22 @@ where
}) })
.collect(); .collect();
join_all(zip_handles).await; // let out: Vec<u64> = join_all(zip_handles)
// .await
// .iter()
// .map(|v| { v.unwrap().join() })
// .collect();
writer.lock().await.finish()?; join_all(zip_handles)
.await
.iter()
.map(|v| {
v.as_ref().unwrap().as_ref().unwrap()
})
.for_each(|bytes| tracing::debug!("bytes written {bytes}"));
writer.lock().unwrap().finish()?;
Ok(()) Ok(())
} }