fix extension method usage

This commit is contained in:
Adam Hathcock
2026-07-28 14:14:55 +01:00
parent c7c1397e1d
commit cfd1699e10
3 changed files with 25 additions and 26 deletions

View File

@@ -313,7 +313,7 @@ internal sealed partial class StreamingZipHeaderFactory
var nextHeaderBytes = await _reader
.ReadUInt32Async(_cancellationToken)
.ConfigureAwait(false);
_sharpCompressStream.Rewind(sizeof(uint));
_sharpCompressStream.RewindBytes(sizeof(uint));
// Check if next data is PostDataDescriptor, streamed file with 0 length
header.HasData = !IsHeader(nextHeaderBytes);

View File

@@ -1,4 +1,3 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
@@ -143,11 +142,11 @@ internal partial class StreamingZipHeaderFactory : ZipHeaderFactory
_lastEntryHeader.IsCrcAvailable = true;
// The DataDescriptor can be either 64bit or 32bit
var compressed_size = reader.ReadUInt32();
var uncompressed_size = reader.ReadUInt32();
var compressedSize = reader.ReadUInt32();
var uncompressedSize = reader.ReadUInt32();
var test_64bit = ((long)uncompressed_size << 32) | compressed_size;
if (test_64bit == _lastEntryHeader.CompressedSize)
var test64Bit = ((long)uncompressedSize << 32) | compressedSize;
if (test64Bit == _lastEntryHeader.CompressedSize)
{
_lastEntryHeader.UncompressedSize =
((long)reader.ReadUInt32() << 32) | headerBytes;
@@ -155,7 +154,7 @@ internal partial class StreamingZipHeaderFactory : ZipHeaderFactory
}
else
{
_lastEntryHeader.UncompressedSize = uncompressed_size;
_lastEntryHeader.UncompressedSize = uncompressedSize;
}
if (pos.HasValue)
@@ -193,34 +192,34 @@ internal partial class StreamingZipHeaderFactory : ZipHeaderFactory
//entry could be zero bytes so we need to know that.
if (header.ZipHeaderType == ZipHeaderType.LocalEntry)
{
var local_header = ((LocalEntryHeader)header);
var dir_header = _entries?.FirstOrDefault(entry =>
entry.Key == local_header.Name
&& local_header.CompressedSize == 0
&& local_header.UncompressedSize == 0
&& local_header.Crc == 0
&& local_header.IsDirectory == false
var localHeader = (LocalEntryHeader)header;
var dirHeader = _entries?.FirstOrDefault(entry =>
entry.Key == localHeader.Name
&& localHeader.CompressedSize == 0
&& localHeader.UncompressedSize == 0
&& localHeader.Crc == 0
&& localHeader.IsDirectory == false
);
if (dir_header != null)
if (dirHeader != null)
{
local_header.UncompressedSize = dir_header.Size;
local_header.CompressedSize = dir_header.CompressedSize;
local_header.Crc = (uint)dir_header.Crc;
local_header.IsCrcAvailable = true;
localHeader.UncompressedSize = dirHeader.Size;
localHeader.CompressedSize = dirHeader.CompressedSize;
localHeader.Crc = (uint)dirHeader.Crc;
localHeader.IsCrcAvailable = true;
}
// If we have CompressedSize, there is data to be read
if (local_header.CompressedSize > 0)
if (localHeader.CompressedSize > 0)
{
header.HasData = true;
} // Check if zip is streaming ( Length is 0 and is declared in PostDataDescriptor )
else if (local_header.Flags.HasFlag(HeaderFlags.UsePostDataDescriptor))
else if (localHeader.Flags.HasFlag(HeaderFlags.UsePostDataDescriptor))
{
// Peek ahead to check if next data is a header or file data.
// Use the IStreamStack.Rewind mechanism to give back the peeked bytes.
var nextHeaderBytes = reader.ReadUInt32();
sharpCompressStream.Rewind(sizeof(uint));
sharpCompressStream.RewindBytes(sizeof(uint));
// Check if next data is PostDataDescriptor, streamed file with 0 length
header.HasData = !IsHeader(nextHeaderBytes);

View File

@@ -622,7 +622,7 @@ internal class ZlibBaseStream : Stream, IStreamStack
// This handles the case where the decompressor over-read past the end of the entry
if (_stream is IStreamStack stack)
{
stack.Rewind(z.AvailableBytesIn);
stack.RewindBytes(z.AvailableBytesIn);
}
z.AvailableBytesIn = 0;
}
@@ -643,7 +643,7 @@ internal class ZlibBaseStream : Stream, IStreamStack
// This handles the case where the decompressor over-read past the end of the entry
if (_stream is IStreamStack stack)
{
stack.Rewind(z.AvailableBytesIn);
stack.RewindBytes(z.AvailableBytesIn);
}
z.AvailableBytesIn = 0;
}
@@ -1023,7 +1023,7 @@ internal class ZlibBaseStream : Stream, IStreamStack
if (rc == ZlibConstants.Z_STREAM_END && z.AvailableBytesIn != 0 && !_wantCompress)
{
//rewind the buffer
this.Rewind(z.AvailableBytesIn);
this.RewindBytes(z.AvailableBytesIn);
z.AvailableBytesIn = 0;
}
@@ -1217,7 +1217,7 @@ internal class ZlibBaseStream : Stream, IStreamStack
if (rc == ZlibConstants.Z_STREAM_END && z.AvailableBytesIn != 0 && !_wantCompress)
{
//rewind the buffer
this.Rewind(z.AvailableBytesIn);
this.RewindBytes(z.AvailableBytesIn);
z.AvailableBytesIn = 0;
}