insert file in zip
This commit is contained in:
parent
3f521b5754
commit
7b6a5980c8
6 changed files with 210 additions and 8 deletions
|
|
@ -166,13 +166,12 @@ impl<T: Write> ZipFileWriter<T> {
|
|||
CompressionMethod::Deflated => {
|
||||
// TODO: find a way to do this in place, the compressed data can be large, and storing it
|
||||
// in memory is bad, but Deflate consume the Reader, so we cannot juste give it self.data
|
||||
// TODO: Compression::default -> nop, use flags
|
||||
// TODO: Compression::default -> use flag?
|
||||
let mut compressor =
|
||||
DeflateEncoder::new(CrcWriter::new(Vec::new()), Compression::default());
|
||||
CrcWriter::new(DeflateEncoder::new(Vec::new(), Compression::default()));
|
||||
io::copy(file, &mut compressor).unwrap();
|
||||
let finished = compressor.finish().unwrap();
|
||||
local_header.crc_32 = finished.crc().sum();
|
||||
finished.into_inner()
|
||||
local_header.crc_32 = compressor.crc().sum();
|
||||
compressor.into_inner().finish().unwrap()
|
||||
}
|
||||
_ => unimplemented!(),
|
||||
};
|
||||
|
|
@ -187,6 +186,12 @@ impl<T: Write> ZipFileWriter<T> {
|
|||
header.set_uncompressed_size(local_header.get_uncompressed_size());
|
||||
header.set_offset_local_header(header_offset);
|
||||
|
||||
// TODO: compression flags are not used right now, set to zero
|
||||
local_header.general_purpose_flags &= !(general_purpose_flags::MASK_COMPRESS_OPTION_1
|
||||
| general_purpose_flags::MASK_COMPRESS_OPTION_2);
|
||||
header.general_purpose_flags &= !(general_purpose_flags::MASK_COMPRESS_OPTION_1
|
||||
| general_purpose_flags::MASK_COMPRESS_OPTION_2);
|
||||
|
||||
let file_info = FileInfo {
|
||||
local_header,
|
||||
header,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue