Set the encrypted file reader length

This commit is contained in:
timvisee 2018-03-06 16:02:33 +01:00
parent ac918cd092
commit e54565724c
No known key found for this signature in database
GPG key ID: 109CBA0BF74036C2

View file

@ -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 {