interpret as bytes by default
This commit is contained in:
parent
efb9c7c39d
commit
24d4b5ac2c
1 changed files with 19 additions and 25 deletions
|
@ -116,17 +116,11 @@ mod dynamic {
|
|||
infer::get_from_path(&path)?
|
||||
.map(|t| (t.matcher_type(), t.extension()))
|
||||
.map(
|
||||
|(matcher, extension)| -> Result<Option<DynamicBendable>, OpenError> {
|
||||
|(matcher, extension)| -> Result<DynamicBendable, OpenError> {
|
||||
Ok(match matcher {
|
||||
Image => Some(DynamicBendable::Image(img::open(path)?)),
|
||||
App | Archive if extension != "pdf" => Some(DynamicBendable::Binary({
|
||||
let mut buf = Vec::new();
|
||||
File::open(path)?.read_to_end(&mut buf)?;
|
||||
buf
|
||||
})),
|
||||
App => unreachable!(),
|
||||
Audio => Some(DynamicBendable::Sound(crate::snd::Audio::open(path)?)),
|
||||
Archive if extension == "pdf" => Some(DynamicBendable::Archive(
|
||||
Image => DynamicBendable::Image(img::open(path)?),
|
||||
Audio => DynamicBendable::Sound(crate::snd::Audio::open(path)?),
|
||||
Archive if extension == "pdf" => DynamicBendable::Archive(
|
||||
PdfDocument::try_from_data_bytes(
|
||||
File::open(path)?
|
||||
.bytes()
|
||||
|
@ -135,39 +129,39 @@ mod dynamic {
|
|||
Default::default(),
|
||||
)
|
||||
.map_err(OpenError::Pdf)?,
|
||||
)),
|
||||
),
|
||||
Archive => {
|
||||
let document_type = DocumentType::from_extension(extension)
|
||||
.ok_or(ShivaUnknownExtensionError)
|
||||
.map_err(ShivaError::UnknownExtension)?;
|
||||
Some(DynamicBendable::Doc(ShivaDocument::new(
|
||||
DynamicBendable::Doc(ShivaDocument::new(
|
||||
Document::parse(
|
||||
&bytes::Bytes::from(std::fs::read(path)?),
|
||||
document_type,
|
||||
)
|
||||
.map_err(ShivaError::Anyhow)?,
|
||||
document_type,
|
||||
)))
|
||||
))
|
||||
}
|
||||
Book => todo!(),
|
||||
Doc => todo!(),
|
||||
Font => todo!(),
|
||||
Text => Some(DynamicBendable::Text(
|
||||
crate::txt::Text::try_from_data_bytes(
|
||||
File::open(path)?
|
||||
.bytes()
|
||||
.collect::<Result<Bytes, io::Error>>()?,
|
||||
(),
|
||||
Default::default(),
|
||||
)?,
|
||||
)),
|
||||
Video => todo!(),
|
||||
Custom => None,
|
||||
Text => DynamicBendable::Text(crate::txt::Text::try_from_data_bytes(
|
||||
File::open(path)?
|
||||
.bytes()
|
||||
.collect::<Result<Bytes, io::Error>>()?,
|
||||
(),
|
||||
Default::default(),
|
||||
)?),
|
||||
_ => DynamicBendable::Binary({
|
||||
let mut buf = Vec::new();
|
||||
File::open(path)?.read_to_end(&mut buf)?;
|
||||
buf
|
||||
}),
|
||||
})
|
||||
},
|
||||
)
|
||||
.transpose()
|
||||
.map(|opt| -> Option<DynamicBendable> { opt? })
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue