-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from nick-cd/stdin-upload
Upload file from stdin
- Loading branch information
Showing
7 changed files
with
98 additions
and
23 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,27 @@ | ||
use std::io; | ||
use std::fs::File; | ||
use std::path::PathBuf; | ||
use mktemp::Temp; | ||
|
||
pub fn stdin_to_file() -> Result<Temp, io::Error> { | ||
let tmp_file = Temp::new_file()?; | ||
let path = tmp_file.as_ref().to_path_buf(); | ||
let mut file = File::create(&path)?; | ||
io::copy(&mut io::stdin(), &mut file)?; | ||
Ok(tmp_file) | ||
} | ||
|
||
pub fn open_file(path: &Option<PathBuf>) -> Result<(File, PathBuf), io::Error> { | ||
match path { | ||
Some(path) => { | ||
let file = File::open(path)?; | ||
Ok((file, path.clone())) | ||
}, | ||
None => { | ||
let tmp_file = stdin_to_file()?; | ||
let path = tmp_file.as_ref().to_path_buf(); | ||
let file = File::open(&path)?; | ||
Ok((file, path)) | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -10,3 +10,4 @@ pub mod id_gen; | |
pub mod md5_writer; | ||
pub mod permission; | ||
pub mod table; | ||
pub mod file_helper; |
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
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