;
pub fn stream_tar_in_thread(path: P) -> Stream
- where P: AsRef + Send + 'static {
+where
+ P: AsRef + Send + 'static,
+{
let (writer, stream) = StreamWriter::new(64);
thread::spawn(move || {
@@ -49,9 +51,7 @@ impl io::Write for StreamWriter {
}
fn flush(&mut self) -> io::Result<()> {
- futures::executor::block_on(async move {
- self.tx.flush().await.ok()
- });
+ futures::executor::block_on(async move { self.tx.flush().await.ok() });
Ok(())
}
}
diff --git a/src/web.rs b/src/web.rs
index 3b361c4..593cbab 100644
--- a/src/web.rs
+++ b/src/web.rs
@@ -1,14 +1,14 @@
-use actix_web::{get, middleware, web, App, Error, HttpServer, HttpRequest, HttpResponse, Responder};
use actix_files::{Files, NamedFile};
+use actix_web::{
+ get, middleware, web, App, Error, HttpRequest, HttpResponse, HttpServer, Responder,
+};
use futures::StreamExt;
use std::path::PathBuf;
-
pub async fn run(bind_addr: &str, root: &PathBuf) -> std::io::Result<()> {
let root_ = root.clone();
let s = HttpServer::new(move || {
-
let static_files = Files::new("/", &root_)
.show_files_listing()
.redirect_to_slash_directory()
@@ -29,18 +29,20 @@ pub async fn run(bind_addr: &str, root: &PathBuf) -> std::io::Result<()> {
}
#[get("/{tail:.*}.tar")]
-async fn handle_tar(req: HttpRequest, root: web::Data, tail: web::Path) -> impl Responder {
+async fn handle_tar(
+ req: HttpRequest,
+ root: web::Data,
+ tail: web::Path,
+) -> impl Responder {
let relpath = PathBuf::from(tail.trim_end_matches('/'));
- let fullpath = root.join(&relpath)
- .canonicalize()
- .unwrap();
-
+ let fullpath = root.join(&relpath).canonicalize().unwrap();
// if a .tar already exists, just return it as-is
let mut fullpath_tar = fullpath.clone();
fullpath_tar.set_extension("tar");
if fullpath_tar.is_file() {
- return NamedFile::open_async(fullpath_tar).await
+ return NamedFile::open_async(fullpath_tar)
+ .await
.unwrap()
.into_response(&req);
}
@@ -49,8 +51,7 @@ async fn handle_tar(req: HttpRequest, root: web::Data, tail: web::Path<
return HttpResponse::NotFound().body("Directory not found\n");
}
- let stream = crate::threaded_archiver::stream_tar_in_thread(fullpath)
- .map(Ok::<_, Error>);
+ let stream = crate::threaded_archiver::stream_tar_in_thread(fullpath).map(Ok::<_, Error>);
let response = HttpResponse::Ok()
.content_type("application/x-tar")
.streaming(stream);