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

View file

@ -4,17 +4,16 @@ use std::io::{Read, Write};
use std::path::Path;
use anyhow::Result;
use rayon::prelude::*;
use zip::ZipArchive;
use crate::model::{Document, ImagePage};
use crate::model::Document;
use super::{FormatReader, FormatWriter};
use super::{CbxReader, FormatReader, FormatWriter};
pub struct CbzReader;
impl FormatReader for CbzReader {
fn read(&self, input: &Path) -> Result<Document> {
impl CbxReader for CbzReader {
fn extract_images(&self, input: &Path) -> Result<Vec<(String, Vec<u8>)>> {
let mut zip = ZipArchive::new(File::open(input)?)?;
let mut files: Vec<(String, Vec<u8>)> = Vec::new();
for i in 0..zip.len() {
@ -35,20 +34,13 @@ impl FormatReader for CbzReader {
));
}
}
Ok(files)
}
}
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))
impl FormatReader for CbzReader {
fn read(&self, input: &Path) -> Result<Document> {
self.read_cbx(input)
}
}