feat: support cbr reading
All checks were successful
Build and test / Tests (pull_request) Successful in 1m12s
Checking yaml / Run yamllint (pull_request) Successful in 4s
Build and test / Build AMD64 (pull_request) Successful in 1m3s
Build and test / Generate Documentation (pull_request) Successful in 58s
Checking Renovate configuration / validate (pull_request) Successful in 1m50s
Build and test / Clippy (pull_request) Successful in 1m2s

This commit is contained in:
Marc Plano-Lesay 2025-10-26 19:14:22 +11:00
parent a16ec085b1
commit 6379e8a56b
Signed by: kernald
GPG key ID: 66A41B08CC62A6CF
10 changed files with 216 additions and 20 deletions

30
src/formats/cbx.rs Normal file
View file

@ -0,0 +1,30 @@
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))
}
}