From 9e0d0d9f6c41e6a6b07e92cbaf7de7782903c244 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Fri, 23 Mar 2018 15:44:34 +0100 Subject: [PATCH] Add Entry::replace_from_buffer() --- lib/core/libimagstore/src/store.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/core/libimagstore/src/store.rs b/lib/core/libimagstore/src/store.rs index a9c3aad8..29dc6890 100644 --- a/lib/core/libimagstore/src/store.rs +++ b/lib/core/libimagstore/src/store.rs @@ -959,6 +959,16 @@ impl Entry { &mut self.content } + /// Replace both header and content of the entry by reading from buffer + /// + /// If an error is returned, the contents of neither the header nor the content are modified. + pub fn replace_from_buffer(&mut self, buf: &str) -> Result<()> { + let (header, content) = ::util::entry_buffer_to_header_content(buf)?; + self.content = content; + self.header = header; + Ok(()) + } + /// Verify the entry. /// /// Currently, this only verifies the header. This might change in the future.