-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove BinaryReader and BinaryWriter references from ZipArchive (#103153
) * Removed BinaryReader, BinaryWriter from ZipArchive and ZipBlocks We now read the data into a (sometimes stack-allocated) byte array and slice it up with BinaryPrimitives. This reduces the number of reads and writes required to read and write a ZipArchive. It also makes future work to enable async APIs easier, since BinaryReader and BinaryWriter lack this support. Also changed approach to reading central file directory headers. Rather than performing X reads per header, we read 4KB of data at a time and look for all applicable headers in that data. This should improve performance when dealing with many small files. * Removed BinaryReader from ZipArchiveEntry This allowed the removal of the ArchiveReader property from ZipArchive. * Removed BinaryWriter from ZipArchiveEntry * Re-adding missing assertion * Reduced memory usage with array pooling Now pooling the file IO buffers and the temporary buffers for extra fields of the CD file header (which would otherwise be allocated and deallocated in a loop.) * Corrected duplicate comment * Added test for changed central directory read method This handles 64x entries with 19-character filenames (and thus, 65-byte file headers.) As a result, it straddles two 4KB read buffers. Also corrected the seek logic while reading the central directory header * Test changes: formatting, converted Theory to Fact * Resolving test failures The buffer returned from the ArrayPool contained older data (including a ZIP header.) When reading the last chunk of the file (i.e a chunk which was less than BackwardsSeekingBufferSize) the buffer's Span wasn't resized to account for this. SeekBackwardsToSignature would thus find the older data, try to seek beyond the end of the stream and fail to read the file. * Responded to code review Reads and writes are now performed using a new set of field lengths and locations. * Code review response Formatting change; added one comment to Zip64EndOfCentralDirectoryLocator.SignatureConstantBytes; clarified comment on ZipHelper.SeekBackwardsAndRead * Additional code review comments Added comment to SeekBackwardsToStream. Lingering references to SignatureConstantBytes.Length. Added two asserts to CanReadLargeCentralDirectoryHeader test, verifying that the archive entry metadata is in a sensible state. --------- Co-authored-by: Carlos Sánchez López <[email protected]>
- Loading branch information
1 parent
4dabc7b
commit 77fc88a
Showing
8 changed files
with
1,031 additions
and
401 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.