Skip to content
Merged
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 @@ -172,9 +172,9 @@ internal async Task LoadCompressedBytesIfNeededAsync(CancellationToken cancellat

for (int i = 0; i < _compressedBytes.Length - 1; i++)
{
await ZipHelper.ReadBytesAsync(_archive.ArchiveStream, _compressedBytes[i], maxSingleBufferSize, cancellationToken).ConfigureAwait(false);
await _archive.ArchiveStream.ReadAtLeastAsync(_compressedBytes[i], maxSingleBufferSize, throwOnEndOfStream: true, cancellationToken).ConfigureAwait(false);
}
await ZipHelper.ReadBytesAsync(_archive.ArchiveStream, _compressedBytes[_compressedBytes.Length - 1], (int)(_compressedSize % maxSingleBufferSize), cancellationToken).ConfigureAwait(false);
await _archive.ArchiveStream.ReadAtLeastAsync(_compressedBytes[_compressedBytes.Length - 1], (int)(_compressedSize % maxSingleBufferSize), throwOnEndOfStream: true, cancellationToken).ConfigureAwait(false);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -678,9 +678,9 @@ internal void LoadCompressedBytesIfNeeded()

for (int i = 0; i < _compressedBytes.Length - 1; i++)
{
ZipHelper.ReadBytes(_archive.ArchiveStream, _compressedBytes[i], maxSingleBufferSize);
_archive.ArchiveStream.ReadAtLeast(_compressedBytes[i], maxSingleBufferSize, throwOnEndOfStream: true);
}
ZipHelper.ReadBytes(_archive.ArchiveStream, _compressedBytes[_compressedBytes.Length - 1], (int)(_compressedSize % maxSingleBufferSize));
_archive.ArchiveStream.ReadAtLeast(_compressedBytes[_compressedBytes.Length - 1], (int)(_compressedSize % maxSingleBufferSize), throwOnEndOfStream: true);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,6 @@ namespace System.IO.Compression;

internal static partial class ZipHelper
{
/// <summary>
/// Asynchronously reads exactly bytesToRead out of stream, unless it is out of bytes.
/// </summary>
internal static async Task<int> ReadBytesAsync(Stream stream, Memory<byte> buffer, int bytesToRead, CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();

int bytesRead = await stream.ReadAtLeastAsync(buffer, bytesToRead, throwOnEndOfStream: false, cancellationToken).ConfigureAwait(false);

if (bytesRead < bytesToRead)
{
throw new IOException(SR.UnexpectedEndOfStream);
}
return bytesRead;
}

// Asynchronously assumes all bytes of signatureToFind are non zero, looks backwards from current position in stream,
// assumes maxBytesToRead is positive, ensures to not read beyond the provided max number of bytes,
// if the signature is found then returns true and positions stream at first byte of signature
Expand Down Expand Up @@ -114,14 +98,14 @@ private static async Task<int> SeekBackwardsAndReadAsync(Stream stream, Memory<b
{
Debug.Assert(overlap <= buffer.Length);
stream.Seek(-(buffer.Length - overlap), SeekOrigin.Current);
bytesRead = await ReadBytesAsync(stream, buffer, buffer.Length, cancellationToken).ConfigureAwait(false);
bytesRead = await stream.ReadAtLeastAsync(buffer, buffer.Length, throwOnEndOfStream: true, cancellationToken).ConfigureAwait(false);
stream.Seek(-buffer.Length, SeekOrigin.Current);
}
else
{
int bytesToRead = (int)stream.Position;
stream.Seek(0, SeekOrigin.Begin);
bytesRead = await ReadBytesAsync(stream, buffer, bytesToRead, cancellationToken).ConfigureAwait(false);
bytesRead = await stream.ReadAtLeastAsync(buffer, bytesToRead, throwOnEndOfStream: true, cancellationToken).ConfigureAwait(false);
stream.Seek(0, SeekOrigin.Begin);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,6 @@ internal static Encoding GetEncoding(string text)
return Encoding.ASCII;
}

/// <summary>
/// Reads exactly bytesToRead out of stream, unless it is out of bytes
/// </summary>
internal static int ReadBytes(Stream stream, Span<byte> buffer, int bytesToRead)
{
int bytesRead = stream.ReadAtLeast(buffer, bytesToRead, throwOnEndOfStream: false);
if (bytesRead < bytesToRead)
{
throw new IOException(SR.UnexpectedEndOfStream);
}
return bytesRead;
}

// will silently return InvalidDateIndicator if the uint is not a valid Dos DateTime
internal static DateTime DosTimeToDateTime(uint dateTime)
{
Expand Down Expand Up @@ -183,14 +170,14 @@ private static int SeekBackwardsAndRead(Stream stream, Span<byte> buffer, int ov
{
Debug.Assert(overlap <= buffer.Length);
stream.Seek(-(buffer.Length - overlap), SeekOrigin.Current);
bytesRead = ReadBytes(stream, buffer, buffer.Length);
bytesRead = stream.ReadAtLeast(buffer, buffer.Length, throwOnEndOfStream: true);
stream.Seek(-buffer.Length, SeekOrigin.Current);
}
else
{
int bytesToRead = (int)stream.Position;
stream.Seek(0, SeekOrigin.Begin);
bytesRead = ReadBytes(stream, buffer, bytesToRead);
bytesRead = stream.ReadAtLeast(buffer, bytesToRead, throwOnEndOfStream: true);
stream.Seek(0, SeekOrigin.Begin);
}

Expand Down
Loading