crier

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

commit 3fcc8f79543a1bb32d1b84080fa7d3388ac041e2
parent 78331aed69f7cd81b2ac231e844585318e1b7ae1
Author: lash <dev@holbrook.no>
Date:   Tue,  9 Jul 2024 00:25:40 +0100

Add entries to feed in sequencer writer

Diffstat:
MCargo.lock | 20+++++++++++++++-----
MCargo.toml | 3++-
Msrc/lib.rs | 26+++++++++++++++++++++-----
Msrc/tests.rs | 14++++++++++----
4 files changed, 48 insertions(+), 15 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock @@ -38,13 +38,13 @@ dependencies = [ [[package]] name = "atom_syndication" version = "0.12.3" -source = "git+git://holbrook.no/contrib/atom_syndication?rev=fab6f733f6481ecfcbd6a76074f1038c79c854ae#fab6f733f6481ecfcbd6a76074f1038c79c854ae" +source = "git+git://holbrook.no/contrib/atom_syndication?rev=9985c1610b2b819f5bd2f7a719567ee0b5419b85#9985c1610b2b819f5bd2f7a719567ee0b5419b85" dependencies = [ "chrono", "derive_builder", "diligent-date-parser", "never", - "quick-xml", + "quick-xml 0.32.0", ] [[package]] @@ -156,7 +156,7 @@ dependencies = [ "http", "itertools", "mediatype", - "quick-xml", + "quick-xml 0.31.0", "rs_sha512", "rss", "serde", @@ -298,7 +298,7 @@ checksum = "be5366c3d4ae865540354ecafa0e5b41dd56c2f31d0b2ef876669edf964daaec" dependencies = [ "chrono", "mediatype", - "quick-xml", + "quick-xml 0.31.0", "regex", "serde", "serde_json", @@ -503,6 +503,16 @@ dependencies = [ ] [[package]] +name = "quick-xml" +version = "0.32.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d3a6e5838b60e0e8fa7a43f22ade549a37d61f8bdbe636d0d7816191de969c2" +dependencies = [ + "encoding_rs", + "memchr", +] + +[[package]] name = "quote" version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -597,7 +607,7 @@ dependencies = [ "atom_syndication", "derive_builder", "never", - "quick-xml", + "quick-xml 0.31.0", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml @@ -29,7 +29,8 @@ atom_syndication = "^0.12" [patch.crates-io] #atom_syndication = { path = "/home/lash/src/contrib/atom_syndication" } -atom_syndication = { git = "git://holbrook.no/contrib/atom_syndication", rev="fab6f733f6481ecfcbd6a76074f1038c79c854ae" } #branch="lash/entry-to-xml" } +#atom_syndication = { git = "git://holbrook.no/contrib/atom_syndication", rev="fab6f733f6481ecfcbd6a76074f1038c79c854ae" } #branch="lash/entry-to-xml" +atom_syndication = { git = "git://holbrook.no/contrib/atom_syndication", rev="9985c1610b2b819f5bd2f7a719567ee0b5419b85" } #branch="lash/entry-fromstr" [dev-dependencies] tempfile = "3.3.0" diff --git a/src/lib.rs b/src/lib.rs @@ -5,6 +5,7 @@ use std::iter::Iterator; use std::io::Write; use std::fmt::Debug; use std::io::BufWriter; +use std::str::FromStr; use feed_rs::model::Entry; use feed_rs::model::Feed; @@ -26,6 +27,7 @@ use cache::Cache; #[derive(Debug)] pub enum Error { WriteError, + CacheError, } @@ -112,6 +114,9 @@ impl<'a> Sequencer<'a> { fn write_to(&mut self, w: impl Write) -> Result<usize, Error> { let mut r: usize; let mut feed = OutFeed::default(); + let mut entry: OutEntry; + let mut entries: Vec<OutEntry>; + let mut b: &str; feed.set_id("urn:uuid:60a76c80-d399-11d9-b91C-0003939e0af6"); feed.set_updated(Local::now().to_utc()); @@ -121,8 +126,24 @@ impl<'a> Sequencer<'a> { }, Ok(_) => { }, + } + entries = Vec::new(); + r = 0; + for v in self { + b = std::str::from_utf8(v.as_slice()).unwrap(); + match OutEntry::from_str(b) { + Err(e) => { + println!("fromstrerr {:?}", e); + return Err(Error::CacheError); + }, + Ok(o) => { + entries.push(o); + }, + } + r += 1; } + feed.set_entries(entries); match feed.write_to(w) { Err(_v) => { @@ -132,11 +153,6 @@ impl<'a> Sequencer<'a> { }, } - r = 0; - for v in self { - r += 1; - } - Ok(r) } } diff --git a/src/tests.rs b/src/tests.rs @@ -1,5 +1,6 @@ use std::clone::Clone; use std::fs::File; +use std::io::{SeekFrom, Seek, Read}; use std::str; use feed_rs::model::Entry; @@ -26,7 +27,7 @@ fn check_xml_title(xml: Vec<u8>, title: &str) { let mut state = 0; loop { match rxml.read_event_into(&mut xmlbuf) { - Err(e) => panic!("cant read back xml"), + Err(e) => panic!("cant read back xml: {:?}", e), Ok(XMLEvent::Eof) => break, Ok(XMLEvent::Start(v)) => { match v.name().as_ref() { @@ -144,7 +145,8 @@ fn test_feed_write() { let r: usize; let fs = FsFeed{}; let f: NamedTempFile; - let fr: File; + let mut fr: File; + //let mut b: [0; 10240]; let feed = fs.get("testdata/test.atom.xml", None).unwrap(); let mut seq = Sequencer::new(); @@ -153,7 +155,11 @@ fn test_feed_write() { fr = f.reopen().unwrap(); r = seq.write_to(f).unwrap(); assert_eq!(r, 15); - assert_eq!(fr.metadata().unwrap().len(), 254); +// let mut b = String::new(); +// fr.seek(SeekFrom::Start(0)); +// fr.read_to_string(&mut b); +// println!("{:?}", b); + assert_eq!(fr.metadata().unwrap().len(), 2521); } #[test] @@ -179,7 +185,7 @@ fn test_feed_write_extcache() { r = seq.write_to(f).unwrap(); assert_eq!(r, 15); - assert_eq!(fr.metadata().unwrap().len(), 254); + assert_eq!(fr.metadata().unwrap().len(), 2521); } #[test]