File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ use std::path::PathBuf;
7
7
use std:: { fs, io} ;
8
8
9
9
#[ derive( Clone ) ]
10
+ /// Defines a data source, either a source `std::path::PathBuf`, or a vector of bytes.
10
11
pub enum FileDataSource {
11
12
File ( PathBuf ) ,
12
13
Data ( Vec < u8 > ) ,
@@ -26,6 +27,7 @@ impl Debug for FileDataSource {
26
27
}
27
28
28
29
impl FileDataSource {
30
+ /// Get the length of the inner data source
29
31
pub fn len ( & self ) -> anyhow:: Result < u64 > {
30
32
Ok ( match self {
31
33
FileDataSource :: File ( path) => fs:: metadata ( path)
@@ -34,7 +36,18 @@ impl FileDataSource {
34
36
FileDataSource :: Data ( v) => v. len ( ) as u64 ,
35
37
} )
36
38
}
37
-
39
+ /// Copy this data source to the specified target that implements io::Write
40
+ /// Example:
41
+ /// ```
42
+ /// let mut new_file = std::io::fs::OpenOptions::new()
43
+ /// .read(true)
44
+ /// .write(true)
45
+ /// .create(true)
46
+ /// .truncate(true)
47
+ /// .open(to)?;
48
+ ///
49
+ /// f.source.copy_to(&mut new_file)?;
50
+ ///```
38
51
pub fn copy_to ( & self , target : & mut dyn io:: Write ) -> anyhow:: Result < ( ) > {
39
52
match self {
40
53
FileDataSource :: File ( file_path) => {
You can’t perform that action at this time.
0 commit comments