From e54565724caee28f67e9fb49ddbe8dbd7b8e8c05 Mon Sep 17 00:00:00 2001 From: timvisee Date: Tue, 6 Mar 2018 16:02:33 +0100 Subject: [PATCH] Set the encrypted file reader length --- src/main.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index f907e5a..141f258 100644 --- a/src/main.rs +++ b/src/main.rs @@ -114,11 +114,12 @@ fn main() { &iv, ); - // Buffer the encrypted reader + // Buffer the encrypted reader, and determine the length + let reader_len = reader.len().unwrap(); let reader = BufReader::new(reader); // Build the file part, configure the form to send - let part = Part::reader(reader) + let part = Part::reader_with_length(reader, reader_len) .file_name(file_name) .mime(APPLICATION_OCTET_STREAM); let form = reqwest::multipart::Form::new() @@ -304,6 +305,12 @@ impl EncryptedFileReaderTagged { tag: None, } } + + /// Calculate the total length of the encrypted file with the appended + /// tag. + pub fn len(&self) -> Result { + Ok(self.file.metadata()?.len() + TAG_LEN as u64) + } } impl Read for EncryptedFileReaderTagged {