diff --git a/lib/sparesults/src/csv.rs b/lib/sparesults/src/csv.rs index 35cff6d2..dc5a6df7 100644 --- a/lib/sparesults/src/csv.rs +++ b/lib/sparesults/src/csv.rs @@ -55,8 +55,9 @@ impl CsvSolutionsWriter { Ok(()) } - pub fn finish(self) -> W { - self.sink + pub fn finish(mut self) -> io::Result { + self.sink.flush()?; + Ok(self.sink) } } @@ -145,8 +146,9 @@ impl TsvSolutionsWriter { Ok(()) } - pub fn finish(self) -> W { - self.sink + pub fn finish(mut self) -> io::Result { + self.sink.flush()?; + Ok(self.sink) } } @@ -319,7 +321,7 @@ mod tests { .filter_map(|(v, s)| s.as_ref().map(|s| (v.as_ref(), s.as_ref()))), )?; } - let result = writer.finish(); + let result = writer.finish()?; assert_eq!(str::from_utf8(&result).unwrap(), "x,literal\r\nhttp://example/x,String\r\nhttp://example/x,\"String-with-dquote\"\"\"\r\n_:b0,Blank node\r\n,Missing 'x'\r\n,\r\nhttp://example/x,\r\n_:b1,String-with-lang\r\n_:b1,123"); Ok(()) } @@ -337,7 +339,7 @@ mod tests { .filter_map(|(v, s)| s.as_ref().map(|s| (v.as_ref(), s.as_ref()))), )?; } - let result = writer.finish(); + let result = writer.finish()?; assert_eq!(str::from_utf8(&result).unwrap(), "?x\t?literal\n\t\"String\"\n\t\"String-with-dquote\\\"\"\n_:b0\t\"Blank node\"\n\t\"Missing 'x'\"\n\t\n\t\n_:b1\t\"String-with-lang\"@en\n_:b1\t123"); Ok(()) } diff --git a/lib/sparesults/src/json.rs b/lib/sparesults/src/json.rs index c7d34fae..dc1661ff 100644 --- a/lib/sparesults/src/json.rs +++ b/lib/sparesults/src/json.rs @@ -66,7 +66,9 @@ impl JsonSolutionsWriter { self.writer.write_event(JsonEvent::EndArray)?; self.writer.write_event(JsonEvent::EndObject)?; self.writer.write_event(JsonEvent::EndObject)?; - Ok(self.writer.into_inner()) + let mut inner = self.writer.into_inner(); + inner.flush()?; + Ok(inner) } } diff --git a/lib/sparesults/src/lib.rs b/lib/sparesults/src/lib.rs index 2e721c6e..e5268cb3 100644 --- a/lib/sparesults/src/lib.rs +++ b/lib/sparesults/src/lib.rs @@ -498,11 +498,11 @@ impl SolutionsWriter { /// Writes the last bytes of the file. pub fn finish(self) -> io::Result { - Ok(match self.formatter { - SolutionsWriterKind::Xml(write) => write.finish()?, - SolutionsWriterKind::Json(write) => write.finish()?, + match self.formatter { + SolutionsWriterKind::Xml(write) => write.finish(), + SolutionsWriterKind::Json(write) => write.finish(), SolutionsWriterKind::Csv(write) => write.finish(), SolutionsWriterKind::Tsv(write) => write.finish(), - }) + } } } diff --git a/lib/sparesults/src/xml.rs b/lib/sparesults/src/xml.rs index 350f2a60..e61d76a1 100644 --- a/lib/sparesults/src/xml.rs +++ b/lib/sparesults/src/xml.rs @@ -85,7 +85,9 @@ impl XmlSolutionsWriter { } pub fn finish(self) -> io::Result { - self.do_finish().map_err(map_xml_error) + let mut inner = self.do_finish().map_err(map_xml_error)?; + inner.flush()?; + Ok(inner) } fn do_finish(mut self) -> Result { diff --git a/lib/src/io/write.rs b/lib/src/io/write.rs index 588a61aa..260b1898 100644 --- a/lib/src/io/write.rs +++ b/lib/src/io/write.rs @@ -144,12 +144,9 @@ impl TripleWriter { /// Writes the last bytes of the file pub fn finish(self) -> io::Result<()> { match self.formatter { - TripleWriterKind::NTriples(_) => (), - TripleWriterKind::RdfXml(formatter) => { - formatter.finish()?; - } - }; - Ok(()) + TripleWriterKind::NTriples(mut writer) => writer.flush(), + TripleWriterKind::RdfXml(formatter) => formatter.finish()?.flush(), //TODO: remove flush when the next version of Rio is going to be released + } } } @@ -259,6 +256,8 @@ impl QuadWriter { /// Writes the last bytes of the file #[allow(clippy::unused_self, clippy::unnecessary_wraps)] pub fn finish(self) -> io::Result<()> { - Ok(()) + match self.formatter { + QuadWriterKind::NQuads(mut writer) | QuadWriterKind::TriG(mut writer) => writer.flush(), + } } }