mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-02-03 21:23:38 +00:00
Read ArchiveComment #231
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @dos-ise on GitHub (Aug 22, 2017).
Is there a way to read an archivecomment?
Found a way to write it but not to read.
@dos-ise commented on GitHub (Jan 18, 2018):
I added a pullrequest for this feature.
https://github.com/adamhathcock/sharpcompress/pull/341
At the moment i am using the follwoing extension.
`using System.IO;
using System.Text;
using System;
using System.Linq;
using System.Reflection;
using SharpCompress.Archives.Zip;
namespace Knx.Ets.Osprey
{
public static class ZipArchiveExtension
{
private const int MAX_ITERATIONS_FOR_DIRECTORY_HEADER = 4096;
}
}
`
@Numpsy commented on GitHub (Dec 14, 2018):
Hi,
I thought this would be a useful feature to have, so I had a look at the code and noticed that ZipArchive.LoadEntries contains code to populate the volume comment from the DirectoryEndHeader, but that didn't seem to be getting called.
I was wondering if doing something like
12a6d3977eto return the DirectoryEndHeader from ReadSeekableHeader in order to populate the volume comment would be a reasonable place to start? (you do have to have loaded the entries before reading the comment from the volume though).@adamhathcock commented on GitHub (Dec 19, 2018):
I'm pretty sure the Archive API uses the dictionary at the end of the file to find entries and seek to them.
Maybe I'm misunderstanding the proposal.
@Numpsy commented on GitHub (Dec 19, 2018):
The ZipArchive.LoadEntries function contains the code
Where the ZipHeaderType.DirectoryEnd case populates the zip volume comment from the comment field in the DirectoryEndHeader.
However, the ReadSeekableHeader function that it calls only seems to return the DirectoryEntryHeader instances, so that case wasn't getting hit.
My thought was that changing ReadSeekableHeader to return the DirectoryEndHeader as well as the DirectoryEntryHeaders would cause the volume comment to be populated (that's what my linked changeset does), which is a means of getting at the comment data at least, even though it's only done when the entries are loaded.
Given that SeekableZipHeaderFactory.ReadSeekableHeader does actually create and populate an instance of DirectoryEndHeader up front (including reading the comment) in order to do the rest of the work, I imagine that you could make use of that directly rather than just returning it at the end of the entries collection? (would be nice to efficiently get the comment out of the file without having to parse the entries if possible). I am however working out how this stuff works as I go along, so i'm not sure of the best aproach to that.
@adamhathcock commented on GitHub (Dec 21, 2018):
I would definitely like to fix the ZipArchive not using the dictionary if that's true. I'm not sure when I'll be able to get around to it over the holiday season and coming months.
I'll have to refresh myself with the zip archive format but if the archive comment has the directory offset then that would definitely be more efficient that backwards scanning which I think I was my previous method.,