Skip to content

Commit 6afdb55

Browse files
committed
src: Implement the missing async methods in internal helper stream classes.
1 parent a87d789 commit 6afdb55

File tree

3 files changed

+46
-4
lines changed

3 files changed

+46
-4
lines changed

src/libraries/System.IO.Compression/src/System/IO/Compression/PositionPreservingWriteOnlyStreamWrapper.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ protected override void Dispose(bool disposing)
9393
_stream.Dispose();
9494
}
9595

96+
public override ValueTask DisposeAsync() => _stream.DisposeAsync();
97+
9698
public override long Length
9799
{
98100
get { throw new NotSupportedException(SR.NotSupported); }
@@ -108,9 +110,10 @@ public override void SetLength(long value)
108110
throw new NotSupportedException(SR.NotSupported);
109111
}
110112

111-
public override int Read(byte[] buffer, int offset, int count)
112-
{
113-
throw new NotSupportedException(SR.NotSupported);
114-
}
113+
public override int Read(byte[] buffer, int offset, int count) => throw new NotSupportedException(SR.NotSupported);
114+
115+
public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) => throw new NotSupportedException(SR.NotSupported);
116+
117+
public override ValueTask<int> ReadAsync(Memory<byte> buffer, CancellationToken cancellationToken = default) => throw new NotSupportedException(SR.NotSupported);
115118
}
116119
}

src/libraries/System.IO.Compression/src/System/IO/Compression/ZipArchiveEntry.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,6 +1437,18 @@ public override int Read(byte[] buffer, int offset, int count)
14371437
throw new NotSupportedException(SR.ReadingNotSupported);
14381438
}
14391439

1440+
public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
1441+
{
1442+
ThrowIfDisposed();
1443+
throw new NotSupportedException(SR.ReadingNotSupported);
1444+
}
1445+
1446+
public override ValueTask<int> ReadAsync(Memory<byte> buffer, CancellationToken cancellationToken = default)
1447+
{
1448+
ThrowIfDisposed();
1449+
throw new NotSupportedException(SR.ReadingNotSupported);
1450+
}
1451+
14401452
public override long Seek(long offset, SeekOrigin origin)
14411453
{
14421454
ThrowIfDisposed();

src/libraries/System.IO.Compression/src/System/IO/Compression/ZipCustomStreams.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,18 @@ public override int Read(byte[] buffer, int offset, int count)
486486
throw new NotSupportedException(SR.ReadingNotSupported);
487487
}
488488

489+
public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
490+
{
491+
ThrowIfDisposed();
492+
throw new NotSupportedException(SR.ReadingNotSupported);
493+
}
494+
495+
public override ValueTask<int> ReadAsync(Memory<byte> buffer, CancellationToken cancellationToken = default)
496+
{
497+
ThrowIfDisposed();
498+
throw new NotSupportedException(SR.ReadingNotSupported);
499+
}
500+
489501
public override long Seek(long offset, SeekOrigin origin)
490502
{
491503
ThrowIfDisposed();
@@ -604,5 +616,20 @@ protected override void Dispose(bool disposing)
604616
}
605617
base.Dispose(disposing);
606618
}
619+
620+
public override async ValueTask DisposeAsync()
621+
{
622+
if (!_isDisposed)
623+
{
624+
// if we never wrote through here, save the position
625+
if (!_everWritten)
626+
_initialPosition = _baseBaseStream.Position;
627+
if (!_leaveOpenOnClose)
628+
await _baseStream.DisposeAsync().ConfigureAwait(false); // Close my super-stream (flushes the last data)
629+
_saveCrcAndSizes?.Invoke(_initialPosition, Position, _checksum, _baseBaseStream, _zipArchiveEntry, _onClose);
630+
_isDisposed = true;
631+
}
632+
await base.DisposeAsync().ConfigureAwait(false);
633+
}
607634
}
608635
}

0 commit comments

Comments
 (0)