kitab

Unnamed repository; edit this file 'description' to name the repository.
Info | Log | Files | Refs | LICENSE

commit bcbc817d44f5ca0e0d8e59521b29ba521f857959
parent 7837a38bdba270b7adbd2bc171f22864f6c619c5
Author: lash <dev@holbrook.no>
Date:   Sun, 26 Jun 2022 16:13:22 +0000

Add file store generator

Diffstat:
Msrc/lib.rs | 2++
Msrc/meta.rs | 10----------
Asrc/store.rs | 48++++++++++++++++++++++++++++++++++++++++++++++++
Atestdata/meta.txt | 6++++++
4 files changed, 56 insertions(+), 10 deletions(-)

diff --git a/src/lib.rs b/src/lib.rs @@ -4,6 +4,8 @@ pub mod meta; pub mod dc; +pub mod store; + #[cfg(feature = "rdf")] pub mod rdf; diff --git a/src/meta.rs b/src/meta.rs @@ -386,16 +386,6 @@ impl MetaData { } } -//impl FromStr for MetaData { -// type Err = std::io::Error; -// -// fn from_str(s: &str) -> Result<MetaData, <MetaData as FromStr>::Err> { -// BufRead -// MetaData::empty(); -// Ok(()) -// } -//} - #[cfg(test)] mod tests { use super::MetaData; diff --git a/src/store.rs b/src/store.rs @@ -0,0 +1,48 @@ +use std::io::Write; +use std::path::{ + PathBuf, + Path, +}; +use std::fs::File; + +use crate::meta::MetaData; + +pub struct FileStore{ + path: PathBuf, +} + +impl FileStore { + pub fn new(p: &Path) -> Self { + FileStore{ + path: p.to_path_buf(), + } + } + + pub fn writer(&self, entry: &MetaData) -> impl Write { + let p = self.path.join(entry.fingerprint()); + File::create(&p).unwrap() + } +} + +#[cfg(test)] +mod tests { + use biblatex::EntryType; + use tempfile::tempdir; + use super::{ + FileStore, + MetaData, + }; + use std::io::Write; + + #[test] + fn test_writer() { + let mut digest = Vec::with_capacity(64); + digest.resize(64, 0x2a); + let m = MetaData::new("foo", "bar", EntryType::Article, Vec::from(digest), None); + let dir = tempdir().unwrap(); + let fp = dir.path(); + let fs = FileStore::new(&fp); + let mut w = fs.writer(&m); + w.write(m.title().as_bytes()); + } +} diff --git a/testdata/meta.txt b/testdata/meta.txt @@ -0,0 +1,6 @@ +Title: foo +Author: bar +Subject: baz +Mime: text/plain +Typ: report +Language: nb-NO