feat: implement cbz writing and pdf reading
All checks were successful
Build and test / Clippy (pull_request) Successful in 44s
Build and test / Tests (pull_request) Successful in 48s
Checking yaml / Run yamllint (pull_request) Successful in 5s
Checking Renovate configuration / validate (pull_request) Successful in 1m4s
Build and test / Build AMD64 (pull_request) Successful in 49s
Build and test / Generate Documentation (pull_request) Successful in 59s
All checks were successful
Build and test / Clippy (pull_request) Successful in 44s
Build and test / Tests (pull_request) Successful in 48s
Checking yaml / Run yamllint (pull_request) Successful in 5s
Checking Renovate configuration / validate (pull_request) Successful in 1m4s
Build and test / Build AMD64 (pull_request) Successful in 49s
Build and test / Generate Documentation (pull_request) Successful in 59s
This commit is contained in:
parent
3aa68fbe12
commit
b35ccbe271
10 changed files with 643 additions and 57 deletions
|
|
@ -8,6 +8,9 @@ use crate::model::Document;
|
|||
pub mod cbz;
|
||||
pub mod pdf;
|
||||
|
||||
use cbz::{CbzReader, CbzWriter};
|
||||
use pdf::{PdfReader, PdfWriter};
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum FormatId {
|
||||
Cbz,
|
||||
|
|
@ -17,18 +20,12 @@ pub enum FormatId {
|
|||
impl FormatId {
|
||||
#[allow(dead_code)]
|
||||
pub fn can_read(self) -> bool {
|
||||
match self {
|
||||
FormatId::Cbz => true,
|
||||
FormatId::Pdf => false, // planned but not implemented yet
|
||||
}
|
||||
get_reader(self).is_some()
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn can_write(self) -> bool {
|
||||
match self {
|
||||
FormatId::Pdf => true,
|
||||
FormatId::Cbz => false, // planned but not implemented yet
|
||||
}
|
||||
get_writer(self).is_some()
|
||||
}
|
||||
|
||||
pub fn detect_from_path(path: &Path) -> Option<FormatId> {
|
||||
|
|
@ -47,3 +44,17 @@ pub trait FormatReader: Send + Sync {
|
|||
pub trait FormatWriter: Send + Sync {
|
||||
fn write(&self, doc: &Document, output: &Path) -> Result<()>;
|
||||
}
|
||||
|
||||
pub fn get_reader(format: FormatId) -> Option<Box<dyn FormatReader>> {
|
||||
match format {
|
||||
FormatId::Cbz => Some(Box::new(CbzReader)),
|
||||
FormatId::Pdf => Some(Box::new(PdfReader)),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_writer(format: FormatId) -> Option<Box<dyn FormatWriter>> {
|
||||
match format {
|
||||
FormatId::Pdf => Some(Box::new(PdfWriter)),
|
||||
FormatId::Cbz => Some(Box::new(CbzWriter)),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue