Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public static async Task<ZipEndOfCentralDirectoryBlock> ReadBlockAsync(Stream st
}
else if (readComment)
{
stream.ReadExactly(eocdBlock._archiveComment);
await stream.ReadExactlyAsync(eocdBlock._archiveComment, cancellationToken).ConfigureAwait(false);
}
return eocdBlock;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -919,5 +919,32 @@ public static async Task ReadAfterSeekingPastEnd_ReturnsZeroBytes(bool async)

await DisposeStream(async, readStream);
}

[Fact]
public static async Task ReadArchiveCommentAsync_DoesNotCallSyncRead()
{
const string ExpectedComment = "this is the archive-level comment";

byte[] zipBytes;
using (MemoryStream buildStream = new MemoryStream())
{
using (ZipArchive archive = new ZipArchive(buildStream, ZipArchiveMode.Create, leaveOpen: true))
{
archive.CreateEntry("file.txt");
archive.Comment = ExpectedComment;
}
zipBytes = buildStream.ToArray();
}

await using MemoryStream ms = new MemoryStream(zipBytes);
await using CallTrackingStream tracker = new CallTrackingStream(ms);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think there is something like AsyncOnlyStream that throws when any synchronous method is used that might be better fit for this kind of test.


ZipArchive readArchive = await ZipArchive.CreateAsync(tracker, ZipArchiveMode.Read, leaveOpen: true, entryNameEncoding: null);
Assert.Equal(ExpectedComment, readArchive.Comment);
await readArchive.DisposeAsync();

Comment on lines +942 to +945
Assert.Equal(0, tracker.TimesCalled(nameof(Stream.Read)));
Assert.Equal(0, tracker.TimesCalled(nameof(Stream.ReadByte)));
}
}
}
Loading