You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jun 2, 2024. It is now read-only.
I don't know what type to pass to ZipWriter::new_append(). Specifically:
When reading an archive, one calls ZipArcihve::new() with a type that implements Read and Seek, such as BufReader<File>.
When writing an archive, one calls ZipWriter::new() with a type that implements Write and Seek, such as BufWriter<File>.
When appending to an archive, one calls ZipWriter::new_append() with... what type?
The problem is that new_append() requires its argument to implement all of Read, Write, and Seek, and no buffering IO wrapper provided by the standard library satisfies those bounds. Just giving it File will work, but won't do any buffering, which is not something you'd want to use in production. External crates such as bufstream don't support seeking. Examples don't appear to show how to invoke ZipWriter::new_append(), and tests only call it with io::Cursor<Vec<u8>>.
Currently I am using this hack helper to achieve this. Is there an easier way?
use std::io::{self,BufReader,BufWriter,Read,Seek,Write};use std::fs::File;pubstructBufReadWrite{r:BufReader<File>,w:BufWriter<File>,}implBufReadWrite{pubfnnew(f:File) -> io::Result<Self>{let fr = f;let fw = fr.try_clone()?;Ok(BufReadWrite{r:BufReader::new(fr),w:BufWriter::new(fw),})}}implReadforBufReadWrite{fnread(&mutself,buf:&mut[u8]) -> io::Result<usize>{self.r.read(buf)}}implWriteforBufReadWrite{fnwrite(&mutself,buf:&[u8]) -> io::Result<usize>{self.w.write(buf)}fnflush(&mutself) -> io::Result<()>{self.w.flush()}}implSeekforBufReadWrite{fnseek(&mutself,pos: io::SeekFrom) -> io::Result<u64>{self.w.flush()?;// BufReader's implementation of Seek::seek() guarantees to immediately// seek the underlying handle even if the seek is within the buffer// bounds. This is why this `seek()` works for writing as well.self.r.seek(pos)}}
I don't know what type to pass to
ZipWriter::new_append(). Specifically:ZipArcihve::new()with a type that implementsReadandSeek, such asBufReader<File>.ZipWriter::new()with a type that implementsWriteandSeek, such asBufWriter<File>.ZipWriter::new_append()with... what type?The problem is that
new_append()requires its argument to implement all ofRead,Write, andSeek, and no buffering IO wrapper provided by the standard library satisfies those bounds. Just giving itFilewill work, but won't do any buffering, which is not something you'd want to use in production. External crates such as bufstream don't support seeking. Examples don't appear to show how to invokeZipWriter::new_append(), and tests only call it withio::Cursor<Vec<u8>>.Currently I am using this
hackhelper to achieve this. Is there an easier way?