Compare commits

..

1 commit

Author SHA1 Message Date
Renovate
7c5a1b2df5 chore(deps): lock file maintenance
All checks were successful
Checking Renovate configuration / validate (pull_request) Successful in 1m23s
Build and test / Build AMD64 (pull_request) Successful in 1m21s
Checking yaml / Run yamllint (pull_request) Successful in 3s
Build and test / Tests (pull_request) Successful in 3m58s
Build and test / Clippy (pull_request) Successful in 4m33s
Build and test / Generate Documentation (pull_request) Successful in 4m0s
2025-10-14 09:30:48 +11:00
11 changed files with 100 additions and 271 deletions

1
.gitignore vendored
View file

@ -1,4 +1,3 @@
.DS_Store
.direnv/
.idea/
/target

175
Cargo.lock generated
View file

@ -136,14 +136,14 @@ checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8"
[[package]]
name = "av1-grain"
version = "0.2.5"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8cfddb07216410377231960af4fcab838eaa12e013417781b78bd95ee22077f8"
checksum = "4f3efb2ca85bc610acfa917b5aaa36f3fcbebed5b3182d7f877b02531c4b80c8"
dependencies = [
"anyhow",
"arrayvec",
"log",
"nom",
"nom 7.1.3",
"num-rational",
"v_frame",
]
@ -165,9 +165,9 @@ checksum = "1e4b40c7323adcfc0a41c4b88143ed58346ff65a288fc144329c5c45e05d70c6"
[[package]]
name = "bitflags"
version = "2.10.0"
version = "2.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3"
checksum = "2261d10cca569e4643e526d8dc2e62e433cc8aba21ab764233731f8d369bf394"
[[package]]
name = "bitstream-io"
@ -225,9 +225,9 @@ checksum = "8f1fe948ff07f4bd06c30984e69f5b4899c516a3ef74f34df92a2df2ab535495"
[[package]]
name = "bzip2"
version = "0.6.1"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f3a53fac24f34a81bc9954b5d6cfce0c21e18ec6959f44f56e8e90e4bb7c346c"
checksum = "bea8dcd42434048e4f7a304411d9273a411f647446c1234a65ce0554923f4cff"
dependencies = [
"libbz2-rs-sys",
]
@ -257,16 +257,15 @@ dependencies = [
"rayon",
"tabled",
"tempfile",
"unrar",
"walkdir",
"zip",
]
[[package]]
name = "cc"
version = "1.2.43"
version = "1.2.41"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "739eb0f94557554b3ca9a86d2d37bebd49c5e6d0c1d2bda35ba5bdac830befc2"
checksum = "ac9fe6cdbb24b6ade63616c0a0688e45bb56732262c158df3c0c4bea4ca47cb7"
dependencies = [
"find-msvc-tools",
"jobserver",
@ -286,9 +285,9 @@ dependencies = [
[[package]]
name = "cfg-if"
version = "1.0.4"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
checksum = "2fd1289c04a9ea8cb22300a459a72a385d7c73d3259e2ed7dcb2af674838cfa9"
[[package]]
name = "chrono"
@ -313,9 +312,9 @@ dependencies = [
[[package]]
name = "clap"
version = "4.5.50"
version = "4.5.49"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c2cfd7bf8a6017ddaa4e32ffe7403d547790db06bd171c1c53926faab501623"
checksum = "f4512b90fa68d3a9932cea5184017c5d200f5921df706d45e853537dea51508f"
dependencies = [
"clap_builder",
"clap_derive",
@ -323,9 +322,9 @@ dependencies = [
[[package]]
name = "clap_builder"
version = "4.5.50"
version = "4.5.49"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0a4c05b9e80c5ccd3a7ef080ad7b6ba7d6fc00a985b8b157197075677c82c7a0"
checksum = "0025e98baa12e766c67ba13ff4695a887a1eba19569aad00a472546795bd6730"
dependencies = [
"anstream",
"anstyle",
@ -470,9 +469,9 @@ checksum = "26bf8fc351c5ed29b5c2f0cbbac1b209b74f60ecd62e675a998df72c49af5204"
[[package]]
name = "deranged"
version = "0.5.5"
version = "0.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ececcb659e7ba858fb4f10388c250a7252eb0a27373f1a72b8748afdd248e587"
checksum = "a41953f86f8a05768a6cda24def994fd2f424b04ec5c719cf89989779f199071"
dependencies = [
"powerfmt",
]
@ -648,9 +647,9 @@ checksum = "52051878f80a721bb68ebfbc930e07b65ba72f2da88968ea5c06fd6ca3d3a127"
[[package]]
name = "flate2"
version = "1.1.5"
version = "1.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bfe33edd8e85a12a67454e37f8c75e730830d83e313556ab9ebf9ee7fbeb3bfb"
checksum = "dc5a4e564e38c699f2880d3fda590bedc2e69f3f84cd48b457bd892ce61d0aa9"
dependencies = [
"crc32fast",
"libz-rs-sys",
@ -681,19 +680,19 @@ checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592"
dependencies = [
"cfg-if",
"libc",
"wasi",
"wasi 0.11.1+wasi-snapshot-preview1",
]
[[package]]
name = "getrandom"
version = "0.3.4"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd"
checksum = "26145e563e54f2cadc477553f1ec5ee650b00862f0a58bcd12cbdc5f0ea2d2f4"
dependencies = [
"cfg-if",
"libc",
"r-efi",
"wasip2",
"wasi 0.14.7+wasi-0.2.4",
]
[[package]]
@ -708,9 +707,9 @@ dependencies = [
[[package]]
name = "half"
version = "2.7.1"
version = "2.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ea2d84b969582b4b1864a92dc5d27cd2b77b622a8d79306834f1be5ba20d84b"
checksum = "e54c115d4f30f52c67202f079c5f9d8b49db4691f460fdb0b4c2e838261b2ba5"
dependencies = [
"cfg-if",
"crunchy",
@ -816,9 +815,9 @@ checksum = "e7c5cedc30da3a610cac6b4ba17597bdf7152cf974e8aab3afb3d54455e371c8"
[[package]]
name = "indexmap"
version = "2.12.0"
version = "2.11.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6717a8d2a5a929a1a2eb43a12812498ed141a0bcfb7e8f7844fbdbe4303bba9f"
checksum = "4b0f83760fb341a774ed326568e19f5a863af4a952def8c39f9ab92fd95b88e5"
dependencies = [
"equivalent",
"hashbrown",
@ -826,9 +825,9 @@ dependencies = [
[[package]]
name = "indicatif"
version = "0.18.1"
version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2e0ddd45fe8e09ee1a607920b12271f8a5528a41ecaf6e1d1440d6493315b6b"
checksum = "70a646d946d06bedbbc4cac4c218acf4bbf2d87757a784857025f4d447e4e1cd"
dependencies = [
"console",
"portable-atomic",
@ -860,20 +859,20 @@ dependencies = [
[[package]]
name = "is-terminal"
version = "0.4.17"
version = "0.4.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3640c1c38b8e4e43584d8df18be5fc6b0aa314ce6ebf51b53313d4306cca8e46"
checksum = "e04d7f318608d35d4b61ddd75cbdaee86b023ebe2bd5a66ee0915f0bf93095a9"
dependencies = [
"hermit-abi",
"libc",
"windows-sys 0.61.2",
"windows-sys 0.59.0",
]
[[package]]
name = "is_terminal_polyfill"
version = "1.70.2"
version = "1.70.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695"
checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf"
[[package]]
name = "itertools"
@ -937,7 +936,7 @@ version = "0.1.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9afb3de4395d6b3e67a780b6de64b51c978ecf11cb9a462c66be7d4ca9039d33"
dependencies = [
"getrandom 0.3.4",
"getrandom 0.3.3",
"libc",
]
@ -1022,13 +1021,13 @@ dependencies = [
"ecb",
"encoding_rs",
"flate2",
"getrandom 0.3.4",
"getrandom 0.3.3",
"indexmap",
"itoa",
"jiff",
"log",
"md-5",
"nom",
"nom 8.0.0",
"nom_locate",
"rand 0.9.2",
"rangemap",
@ -1077,6 +1076,12 @@ version = "2.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273"
[[package]]
name = "minimal-lexical"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
[[package]]
name = "miniz_oxide"
version = "0.8.9"
@ -1103,6 +1108,16 @@ version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086"
[[package]]
name = "nom"
version = "7.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"
dependencies = [
"memchr",
"minimal-lexical",
]
[[package]]
name = "nom"
version = "8.0.0"
@ -1120,7 +1135,7 @@ checksum = "0b577e2d69827c4740cba2b52efaad1c4cc7c73042860b199710b3575c68438d"
dependencies = [
"bytecount",
"memchr",
"nom",
"nom 8.0.0",
]
[[package]]
@ -1193,9 +1208,9 @@ checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
[[package]]
name = "once_cell_polyfill"
version = "1.70.2"
version = "1.70.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe"
checksum = "a4895175b425cb1f87721b59f0f286c2092bd4af812243672510e1ac53e2e0ad"
[[package]]
name = "papergrid"
@ -1325,9 +1340,9 @@ dependencies = [
[[package]]
name = "proc-macro2"
version = "1.0.103"
version = "1.0.101"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ee95bc4ef87b8d5ba32e8b7714ccc834865276eab0aed5c9958d00ec45f49e8"
checksum = "89ae43fd86e4158d6db51ad8e2b80f313af9cc74f5c0e03ccb87de09998732de"
dependencies = [
"unicode-ident",
]
@ -1446,7 +1461,7 @@ version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38"
dependencies = [
"getrandom 0.3.4",
"getrandom 0.3.3",
]
[[package]]
@ -1712,9 +1727,9 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
[[package]]
name = "syn"
version = "2.0.108"
version = "2.0.106"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da58917d35242480a05c2897064da0a80589a2a0476c9a3f2fdc83b53502e917"
checksum = "ede7c438028d4436d71104916910f5bb611972c5cfd7f89b8300a8186e6fada6"
dependencies = [
"proc-macro2",
"quote",
@ -1771,7 +1786,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2d31c77bdf42a745371d260a26ca7163f1e0924b64afa0b688e61b5a9fa02f16"
dependencies = [
"fastrand",
"getrandom 0.3.4",
"getrandom 0.3.3",
"once_cell",
"rustix",
"windows-sys 0.61.2",
@ -1949,9 +1964,9 @@ checksum = "5c1cb5db39152898a79168971543b1cb5020dff7fe43c8dc468b0885f5e29df5"
[[package]]
name = "unicode-ident"
version = "1.0.20"
version = "1.0.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "462eeb75aeb73aea900253ce739c8e18a67423fadf006037cd3ff27e82748a06"
checksum = "f63a545481291138910575129486daeaf8ac54aee4387fe7906919f7830c7d9d"
[[package]]
name = "unicode-normalization"
@ -1980,29 +1995,6 @@ version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "323402cff2dd658f39ca17c789b502021b3f18707c91cdf22e3838e1b4023817"
[[package]]
name = "unrar"
version = "0.5.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "92ec61343a630d2b50d13216dea5125e157d3fc180a7d3f447d22fe146b648fc"
dependencies = [
"bitflags",
"regex",
"unrar_sys",
"widestring",
]
[[package]]
name = "unrar_sys"
version = "0.5.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b77675b883cfbe6bf41e6b7a5cd6008e0a83ba497de3d96e41a064bbeead765"
dependencies = [
"cc",
"libc",
"winapi",
]
[[package]]
name = "utf8parse"
version = "0.2.2"
@ -2048,6 +2040,15 @@ version = "0.11.1+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b"
[[package]]
name = "wasi"
version = "0.14.7+wasi-0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "883478de20367e224c0090af9cf5f9fa85bed63a95c1abf3afc5c083ebc06e8c"
dependencies = [
"wasip2",
]
[[package]]
name = "wasip2"
version = "1.0.1+wasi-0.2.4"
@ -2132,28 +2133,6 @@ version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a751b3277700db47d3e574514de2eced5e54dc8a5436a3bf7a0b248b2cee16f3"
[[package]]
name = "widestring"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72069c3113ab32ab29e5584db3c6ec55d416895e60715417b5b883a357c3e471"
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-util"
version = "0.1.11"
@ -2163,12 +2142,6 @@ dependencies = [
"windows-sys 0.61.2",
]
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "windows-core"
version = "0.62.2"
@ -2452,7 +2425,7 @@ dependencies = [
"crc32fast",
"deflate64",
"flate2",
"getrandom 0.3.4",
"getrandom 0.3.3",
"hmac",
"indexmap",
"lzma-rust2",

View file

@ -17,7 +17,6 @@ tabled = "0.20.0"
walkdir = "2.5.0"
zip = "6.0.0"
lopdf = "0.38.0"
unrar = "0.5.8"
tempfile = "3.12.0"
[dev-dependencies]
tempfile = "3.12.0"

12
flake.lock generated
View file

@ -57,11 +57,11 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1761114652,
"narHash": "sha256-f/QCJM/YhrV/lavyCVz8iU3rlZun6d+dAiC3H+CDle4=",
"lastModified": 1760284886,
"narHash": "sha256-TK9Kr0BYBQ/1P5kAsnNQhmWWKgmZXwUQr4ZMjCzWf2c=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "01f116e4df6a15f4ccdffb1bcd41096869fb385c",
"rev": "cf3f5c4def3c7b5f1fc012b3d839575dbe552d43",
"type": "github"
},
"original": {
@ -80,11 +80,11 @@
]
},
"locked": {
"lastModified": 1760663237,
"narHash": "sha256-BflA6U4AM1bzuRMR8QqzPXqh8sWVCNDzOdsxXEguJIc=",
"lastModified": 1760392170,
"narHash": "sha256-WftxJgr2MeDDFK47fQKywzC72L2jRc/PWcyGdjaDzkw=",
"owner": "cachix",
"repo": "git-hooks.nix",
"rev": "ca5b894d3e3e151ffc1db040b6ce4dcc75d31c37",
"rev": "46d55f0aeb1d567a78223e69729734f3dca25a85",
"type": "github"
},
"original": {

View file

@ -1,75 +0,0 @@
use std::ffi::OsStr;
use std::fs;
use std::io::Read;
use std::path::{Path, PathBuf};
use anyhow::{anyhow, Result};
use walkdir::WalkDir;
use crate::model::Document;
use super::{CbxReader, FormatReader};
pub struct CbrReader;
impl CbxReader for CbrReader {
fn extract_images(&self, input: &Path) -> Result<Vec<(String, Vec<u8>)>> {
let tempdir = tempfile::tempdir()?;
let dest = tempdir.path().to_path_buf();
{
use std::env;
use unrar::Archive;
let cwd = env::current_dir()?;
let input_str = input.to_string_lossy().to_string();
env::set_current_dir(&dest)?;
let mut archive = Archive::new(&input_str)
.open_for_processing()
.map_err(|e| anyhow!("Failed to open RAR for processing: {e}"))?;
loop {
match archive.read_header() {
Ok(Some(header)) => {
archive = if header.entry().is_file() {
header
.extract()
.map_err(|e| anyhow!("Failed to extract entry: {e}"))?
} else {
header
.skip()
.map_err(|e| anyhow!("Failed to skip entry: {e}"))?
};
}
Ok(None) => break,
Err(e) => {
let _ = env::set_current_dir(cwd);
return Err(anyhow!("Failed to read RAR header: {e}"));
}
}
}
env::set_current_dir(cwd)?;
}
let mut files: Vec<(String, Vec<u8>)> = Vec::new();
for entry in WalkDir::new(&dest).into_iter().filter_map(Result::ok) {
let path: PathBuf = entry.path().to_path_buf();
if path.is_file() && path.extension() == Some(OsStr::new("jpg")) {
let mut data = Vec::new();
fs::File::open(&path)?.read_to_end(&mut data)?;
let name = path
.file_name()
.and_then(OsStr::to_str)
.map(|s| s.to_string())
.unwrap_or_else(|| path.display().to_string());
files.push((name, data));
}
}
Ok(files)
}
}
impl FormatReader for CbrReader {
fn read(&self, input: &Path) -> Result<Document> {
self.read_cbx(input)
}
}

View file

@ -1,30 +0,0 @@
use anyhow::Result;
use std::path::Path;
use crate::model::Document;
// Shared reader logic for CBx (CBZ/CBR) formats
pub trait CbxReader: Send + Sync {
// Implementors should return a list of (file_name, jpeg_bytes)
fn extract_images(&self, input: &Path) -> Result<Vec<(String, Vec<u8>)>>;
// Build a Document from extracted JPEG bytes
fn read_cbx(&self, input: &Path) -> Result<Document> {
let files = self.extract_images(input)?;
let mut pages: Vec<crate::model::ImagePage> = Vec::new();
{
use rayon::prelude::*;
files
.par_iter()
.map(|(name, data)| crate::model::ImagePage {
name: name.clone(),
image: image::load_from_memory(data).expect("Failed to decode image"),
jpeg_dct: Some(data.clone()),
})
.collect_into_vec(&mut pages);
pages.par_sort_by_key(|p| p.name.clone());
}
Ok(Document::new(pages))
}
}

View file

@ -4,16 +4,17 @@ use std::io::{Read, Write};
use std::path::Path;
use anyhow::Result;
use rayon::prelude::*;
use zip::ZipArchive;
use crate::model::Document;
use crate::model::{Document, ImagePage};
use super::{CbxReader, FormatReader, FormatWriter};
use super::{FormatReader, FormatWriter};
pub struct CbzReader;
impl CbxReader for CbzReader {
fn extract_images(&self, input: &Path) -> Result<Vec<(String, Vec<u8>)>> {
impl FormatReader for CbzReader {
fn read(&self, input: &Path) -> Result<Document> {
let mut zip = ZipArchive::new(File::open(input)?)?;
let mut files: Vec<(String, Vec<u8>)> = Vec::new();
for i in 0..zip.len() {
@ -34,13 +35,20 @@ impl CbxReader for CbzReader {
));
}
}
Ok(files)
}
}
impl FormatReader for CbzReader {
fn read(&self, input: &Path) -> Result<Document> {
self.read_cbx(input)
let mut pages: Vec<ImagePage> = Vec::new();
files
.par_iter()
.map(|(name, data)| ImagePage {
name: name.clone(),
image: image::load_from_memory(data).expect("Failed to decode image"),
jpeg_dct: Some(data.clone()),
})
.collect_into_vec(&mut pages);
pages.par_sort_by_key(|p| p.name.clone());
Ok(Document::new(pages))
}
}

View file

@ -5,14 +5,9 @@ use anyhow::Result;
use crate::model::Document;
pub mod cbr;
pub mod cbx;
pub mod cbz;
pub mod pdf;
pub use cbx::CbxReader;
use cbr::CbrReader;
use cbz::{CbzReader, CbzWriter};
use pdf::{PdfReader, PdfWriter};
@ -20,7 +15,6 @@ use pdf::{PdfReader, PdfWriter};
pub enum FormatId {
Cbz,
Pdf,
Cbr,
}
impl FormatId {
@ -38,7 +32,6 @@ impl FormatId {
match path.extension().and_then(OsStr::to_str) {
Some("cbz") => Some(FormatId::Cbz),
Some("pdf") => Some(FormatId::Pdf),
Some("cbr") => Some(FormatId::Cbr),
_ => None,
}
}
@ -56,7 +49,6 @@ pub fn get_reader(format: FormatId) -> Option<Box<dyn FormatReader>> {
match format {
FormatId::Cbz => Some(Box::new(CbzReader)),
FormatId::Pdf => Some(Box::new(PdfReader)),
FormatId::Cbr => Some(Box::new(CbrReader)),
}
}
@ -64,6 +56,5 @@ pub fn get_writer(format: FormatId) -> Option<Box<dyn FormatWriter>> {
match format {
FormatId::Pdf => Some(Box::new(PdfWriter)),
FormatId::Cbz => Some(Box::new(CbzWriter)),
FormatId::Cbr => None,
}
}

View file

@ -21,7 +21,6 @@ impl Job {
match to {
FormatId::Pdf => output_path.set_extension("pdf"),
FormatId::Cbz => output_path.set_extension("cbz"),
FormatId::Cbr => output_path.set_extension("cbr"),
};
Self {

View file

@ -1,23 +0,0 @@
use std::fs::File;
use std::io::Write;
use cbz2pdf::formats::cbr::CbrReader;
use cbz2pdf::formats::FormatReader;
// We cannot reliably create a RAR archive in tests (tools cannot create .rar),
// Instead, verify that the reader fails gracefully (returns an error) when given an invalid .cbr
// file.
#[test]
fn cbr_reader_errors_on_invalid_archive() {
let temp_dir = tempfile::tempdir().expect("create temp dir");
let cbr_path = temp_dir.path().join("invalid.cbr");
// Write some junk that is definitely not a RAR archive
let mut f = File::create(&cbr_path).expect("create cbr");
f.write_all(b"this is not a rar archive").unwrap();
let reader = CbrReader;
let res = reader.read(&cbr_path);
assert!(res.is_err(), "CbrReader should error on invalid archives");
}

View file

@ -7,10 +7,8 @@ use cbz2pdf::job::Job;
fn detect_from_path_recognizes_extensions() {
let cbz = PathBuf::from("/tmp/book.cbz");
let pdf = PathBuf::from("/tmp/book.pdf");
let cbr = PathBuf::from("/tmp/book.cbr");
assert_eq!(FormatId::detect_from_path(&cbz), Some(FormatId::Cbz));
assert_eq!(FormatId::detect_from_path(&pdf), Some(FormatId::Pdf));
assert_eq!(FormatId::detect_from_path(&cbr), Some(FormatId::Cbr));
assert_eq!(
FormatId::detect_from_path(&PathBuf::from("/tmp/book.txt")),
None
@ -26,19 +24,11 @@ fn job_new_sets_output_extension() {
let job2 = Job::new(
PathBuf::from("/tmp/book.pdf"),
outdir.clone(),
outdir,
FormatId::Pdf,
FormatId::Cbz,
);
assert!(job2.output_path.ends_with("book.cbz"));
let job3 = Job::new(
PathBuf::from("/tmp/book.cbz"),
outdir,
FormatId::Cbz,
FormatId::Cbr,
);
assert!(job3.output_path.ends_with("book.cbr"));
}
#[test]
@ -47,6 +37,4 @@ fn format_capabilities_consistent() {
assert!(FormatId::Cbz.can_write());
assert!(FormatId::Pdf.can_write());
assert!(FormatId::Pdf.can_read());
assert!(FormatId::Cbr.can_read());
assert!(!FormatId::Cbr.can_write());
}