aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorA Farzat <a@farzat.xyz>2026-03-03 13:11:57 +0300
committerA Farzat <a@farzat.xyz>2026-03-03 13:15:52 +0300
commit9a95cf1684fcd8bfc81efcac7676532413d35328 (patch)
treee04bc487509f6b09efcbb1c74c5f07dfa9f46989 /src
parentdc57dd6437e36fe3bca44cda623879f2b701371d (diff)
downloadoreilly-epub-9a95cf1684fcd8bfc81efcac7676532413d35328.tar.gz
oreilly-epub-9a95cf1684fcd8bfc81efcac7676532413d35328.zip
Start with the create_epub_archive function
For now, only mimetype is added. Next step is adding all the other files in epub_root.
Diffstat (limited to 'src')
-rw-r--r--src/epub.rs16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/epub.rs b/src/epub.rs
index d86fa35..e71e3ca 100644
--- a/src/epub.rs
+++ b/src/epub.rs
@@ -1,11 +1,12 @@
use crate::models::FileEntry;
use anyhow::Result;
use reqwest::Client;
-use std::path::Path;
+use std::{io::Write, path::Path};
use tokio::{
fs::{self, File},
io::AsyncWriteExt,
};
+use zip::{CompressionMethod, ZipWriter, write::FileOptions};
/// Creates and writes container.xml.
pub async fn write_container_xml(dest_root: &Path, opf_full_path: &str) -> Result<()> {
@@ -58,3 +59,16 @@ pub async fn download_all_files(
}
Ok(())
}
+
+/// Creates the EPUB archive (creates zip and includes all files in it).
+pub fn create_epub_archive(epub_root: &Path, output_epub: &Path) -> Result<()> {
+ let out_file = std::fs::File::create(output_epub)?;
+ let mut zip = ZipWriter::new(out_file);
+
+ let mimetype_options: FileOptions<()> =
+ FileOptions::default().compression_method(CompressionMethod::Stored);
+ zip.start_file("mimetype", mimetype_options)?;
+ zip.write_all(b"application/epub+zip")?;
+
+ Ok(())
+}