Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ArchiveComment Property to ZipArchive #341

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/SharpCompress/Archives/Zip/ZipArchive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public class ZipArchive : AbstractWritableArchive<ZipArchiveEntry, ZipVolume>
/// </summary>
public CompressionLevel DeflateCompressionLevel { get; set; }

public string ArchiveComment { get; private set; }

#if !NO_FILE

/// <summary>
Expand Down Expand Up @@ -154,6 +156,7 @@ protected override IEnumerable<ZipArchiveEntry> LoadEntries(IEnumerable<ZipVolum
{
case ZipHeaderType.DirectoryEntry:
{
this.ArchiveComment = (h as DirectoryEntryHeader).Comment;
yield return new ZipArchiveEntry(this,
new SeekableZipFilePart(headerFactory,
h as DirectoryEntryHeader,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,6 @@ internal override void Read(BinaryReader reader)

public ushort DiskNumberStart { get; set; }

public string Comment { get; private set; }
public string Comment { get; set; }
}
}
7 changes: 6 additions & 1 deletion src/SharpCompress/Common/Zip/SeekableZipHeaderFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ internal IEnumerable<DirectoryEntryHeader> ReadSeekableHeader(Stream stream)
SeekBackToHeader(stream, reader, DIRECTORY_END_HEADER_BYTES);
var entry = new DirectoryEndHeader();
entry.Read(reader);

var comm = new ArchiveEncoding().Decode(entry.Comment);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't going to work properly. The instance of the encoding object needs to be passed from options. Maybe don't worry about decoding it yet.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, i moved the decoding to ZipArchive.

I didn't want to change the type of Comment property on DirectoryEntryHeader.
So i converted the hex array to string and back.

if (entry.IsZip64)
{
_zip64 = true;
Expand Down Expand Up @@ -58,6 +58,11 @@ internal IEnumerable<DirectoryEntryHeader> ReadSeekableHeader(Stream stream)
yield break;
}

if (!string.IsNullOrEmpty(comm))
{
directoryEntryHeader.Comment = comm;
}

//entry could be zero bytes so we need to know that.
directoryEntryHeader.HasData = directoryEntryHeader.CompressedSize != 0;
yield return directoryEntryHeader;
Expand Down