Skip to content

Commit

Permalink
Write Zip
Browse files Browse the repository at this point in the history
  • Loading branch information
connorslade committed Nov 3, 2023
1 parent 44e4547 commit b9f5a37
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use std::{
fs::{self, File},
io::Write,
path::Path,
sync::Arc,
};
Expand All @@ -14,6 +15,7 @@ use serde::Serialize;
use serde_json::json;
use url::Url;
use uuid::Uuid;
use zip::ZipWriter;

mod download;
mod extract;
Expand All @@ -34,6 +36,11 @@ fn main() -> Result<()> {
let images = download::download(OUT_DIR, assets);
println!("[*] Downloaded {} images", images.len());

match compress(&images) {
Ok(()) => println!("[*] Compressed images"),
Err(e) => println!("[!] Failed to compress images: {}", e),
};

let date = chrono::offset::Local::now().with_timezone(&Utc);
let info_file = File::create_new(format!("{OUT_DIR}/info.json"))?;
serde_json::to_writer(
Expand All @@ -46,6 +53,20 @@ fn main() -> Result<()> {
Ok(())
}

fn compress(images: &[ImageRef]) -> Result<()> {
let file = File::create(format!("{OUT_DIR}/all.zip"))?;
let mut zip = ZipWriter::new(file);

for i in images {
zip.start_file(format!("{}.bmp", i.uuid), Default::default())?;
let data = fs::read(format!("{OUT_DIR}/{}.bmp", i.uuid))?;
zip.write_all(&data)?;
}

zip.finish()?;
Ok(())
}

#[derive(Serialize, Clone)]
pub struct Post {
post: u32,
Expand Down

0 comments on commit b9f5a37

Please sign in to comment.