-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
86 additions
and
4 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use std::io::{self, Read, Write}; | ||
use uuid::Uuid; | ||
|
||
pub struct MultipartWriter { | ||
boundary: String, | ||
pub data: Vec<u8>, | ||
first: bool, | ||
} | ||
|
||
impl MultipartWriter { | ||
pub fn new() -> MultipartWriter { | ||
MultipartWriter { | ||
boundary: format!("boundary-{}", Uuid::new_v4()), | ||
first: true, | ||
data: Vec::new(), | ||
} | ||
} | ||
|
||
pub fn new_with_boundary(boundary: &str) -> MultipartWriter { | ||
MultipartWriter { | ||
boundary: boundary.to_string(), | ||
first: true, | ||
data: Vec::new(), | ||
} | ||
} | ||
|
||
pub fn add(self: &mut Self, reader: &mut dyn Read) -> io::Result<u64> { | ||
// writer for the result | ||
let mut writer = std::io::BufWriter::new(&mut self.data); | ||
|
||
// write the boundary | ||
if !self.first { | ||
writer.write_all(b"\r\n").unwrap(); | ||
} | ||
|
||
writer.write_all(b"--").unwrap(); | ||
writer.write_all(self.boundary.as_bytes()).unwrap(); | ||
writer.write_all(b"\r\n").unwrap(); | ||
|
||
// write the content | ||
io::copy(reader, &mut writer) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
mod builder; | ||
mod extractor; | ||
mod reader; | ||
|
||
pub use builder::*; | ||
pub use reader::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters