Function write

Source
pub fn write<W: Write + Seek, R: Read, F: Fn(&Path) -> Result<R, Error>, P: AsRef<Path>>(
    paths: &[P],
    dest: W,
    open: F,
) -> Result<(), Error>
Expand description

Bundle data from paths opened using the open function, and used to write to dest. open can be used to preprocess files without using files to store temporary data; everything can be in memory. paths order will be the same as in the resulting bundle. dest should not be buffered; only large chunks are written.

ยงErrors

This function will try to read from the supplied Read from open function. Then it will write to dest and Write::flush() it.

Examples found in repository?
examples/main.rs (lines 66-68)
54fn package_all<P1: AsRef<Path>, P2: AsRef<Path>>(
55    dir: P1,
56    dest: Option<P2>,
57) -> Result<(), serialize::Error> {
58    let paths = walk_dir(&dir, &|_| true).map_err(serialize::Error::Reader)?;
59
60    let dest_path = match dest.as_ref() {
61        Some(dest) => Cow::Borrowed(dest.as_ref()),
62        None => Cow::Owned(dir.as_ref().with_extension("b")),
63    };
64    let dest = fs::File::create(&dest_path).map_err(serialize::Error::Writer)?;
65
66    write(&paths, dest, |path| {
67        fs::File::open(path).map_err(serialize::Error::Reader)
68    })
69}