浏览代码

Set the encrypted file reader length

timvisee 7 年之前
父节点
当前提交
e54565724c
共有 1 个文件被更改,包括 9 次插入2 次删除
  1. 9 2
      src/main.rs

+ 9 - 2
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<u64, io::Error> {
+        Ok(self.file.metadata()?.len() + TAG_LEN as u64)
+    }
 }
 
 impl Read for EncryptedFileReaderTagged {