Majored / rs-async-zip

An asynchronous ZIP archive reading/writing crate.
MIT License
123 stars 40 forks source link

Offset and size of entry in archive #113

Open baszalmstra opened 8 months ago

baszalmstra commented 8 months ago

Im working on reading zip files over http using http ranges. To do that correctly I first fetch the last couple of bytes from archive to read the central directory following by reading the bytes for a specific file.

However, this library does not provide me with the exact number of bytes for a single file.

I can use something along the lines of:

let entry = reader.file().entries().get(0).unwrap();
let offset = entry.header_offset();
// Get the size of the entry plus the header + size of the filename. We should also actually
// include bytes for the extra fields but we don't have that information.
let size = entry.entry().compressed_size() + 30 + entry.entry().filename().as_bytes().len();

but the computation of the size is fairly magical and incorrect if the header contains extra fields.

What would be a "nicer" way to get this information? Would it be possible to add a function that returns the total size of the file in the archive from a StoredZipEntry?

startewho commented 7 months ago

may be add a heder_size() function,that can use header_offset()+ heder_size() get the offet in the archive