]> git.proxmox.com Git - pxar.git/commitdiff
encoder: flush after writing last entry
authorDominik Csapak <d.csapak@proxmox.com>
Wed, 24 Mar 2021 10:56:38 +0000 (11:56 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Thu, 25 Mar 2021 06:31:16 +0000 (07:31 +0100)
some writers may need to be flushed to write out all data

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
src/encoder/mod.rs

index 1004efaf9aba9e9cb3658c2250d5e2e386530652..c1146573e8fb78aad40047aa8a6dd017b863272a 100644 (file)
@@ -83,6 +83,13 @@ async fn seq_write<T: SeqWrite + ?Sized>(
     Ok(put)
 }
 
+/// awaitable version of 'poll_flush'.
+async fn flush<T: SeqWrite + ?Sized>(
+    output: &mut T,
+) -> io::Result<()> {
+    poll_fn(|cx| unsafe { Pin::new_unchecked(&mut *output).poll_flush(cx) }).await
+}
+
 /// Write the entire contents of a buffer, handling short writes.
 async fn seq_write_all<T: SeqWrite + ?Sized>(
     output: &mut T,
@@ -715,6 +722,8 @@ impl<'a, T: SeqWrite + 'a> EncoderImpl<'a, T> {
         )
         .await?;
 
+        flush(self.output.as_mut()).await?;
+
         // done up here because of the self-borrow and to propagate
         let end_offset = self.position();