|
2 | 2 | // The .NET Foundation licenses this file to you under the MIT license. |
3 | 3 |
|
4 | 4 | using System.Runtime.InteropServices; |
5 | | -using System.Threading; |
6 | 5 | using System.Threading.Tasks; |
7 | 6 | using Xunit; |
8 | 7 |
|
@@ -52,118 +51,5 @@ public static async Task RoundTrips_UnixFilePermissions(int expectedAttr) |
52 | 51 | } |
53 | 52 | } |
54 | 53 | } |
55 | | - |
56 | | - [Fact] |
57 | | - public static async Task AsyncOnlyStream_NoSynchronousCalls() |
58 | | - { |
59 | | - // This test verifies that async Zip methods don't make synchronous calls |
60 | | - // which would fail with async-only streams (e.g., Kestrel response streams) |
61 | | - var innerStream = new MemoryStream(); |
62 | | - var asyncOnlyStream = new AsyncOnlyStream(innerStream); |
63 | | - byte[] testData = new byte[1024]; |
64 | | - Random.Shared.NextBytes(testData); |
65 | | - |
66 | | - await using (var zipArchive = new ZipArchive(asyncOnlyStream, ZipArchiveMode.Create, leaveOpen: true)) |
67 | | - { |
68 | | - var entry = zipArchive.CreateEntry("TestEntry"); |
69 | | - await using (var entryStream = await entry.OpenAsync()) |
70 | | - { |
71 | | - await entryStream.WriteAsync(testData); |
72 | | - await entryStream.FlushAsync(); |
73 | | - } |
74 | | - } |
75 | | - |
76 | | - // Verify the archive was created successfully by reading from the inner stream |
77 | | - innerStream.Position = 0; |
78 | | - using (var zipArchive = new ZipArchive(innerStream, ZipArchiveMode.Read)) |
79 | | - { |
80 | | - Assert.Single(zipArchive.Entries); |
81 | | - var entry = zipArchive.Entries[0]; |
82 | | - Assert.Equal("TestEntry", entry.Name); |
83 | | - Assert.Equal(testData.Length, entry.Length); |
84 | | - |
85 | | - using (var entryStream = entry.Open()) |
86 | | - { |
87 | | - byte[] readData = new byte[testData.Length]; |
88 | | - int bytesRead = entryStream.Read(readData); |
89 | | - Assert.Equal(testData.Length, bytesRead); |
90 | | - Assert.Equal(testData, readData); |
91 | | - } |
92 | | - } |
93 | | - } |
94 | | - |
95 | | - private sealed class AsyncOnlyStream : Stream |
96 | | - { |
97 | | - private readonly MemoryStream _innerStream; |
98 | | - |
99 | | - public AsyncOnlyStream(MemoryStream innerStream) |
100 | | - { |
101 | | - _innerStream = innerStream; |
102 | | - } |
103 | | - |
104 | | - public override void Flush() |
105 | | - { |
106 | | - throw new NotSupportedException("Synchronous operations not supported"); |
107 | | - } |
108 | | - |
109 | | - public override int Read(byte[] buffer, int offset, int count) |
110 | | - { |
111 | | - throw new NotSupportedException("Synchronous operations not supported"); |
112 | | - } |
113 | | - |
114 | | - public override long Seek(long offset, SeekOrigin origin) |
115 | | - { |
116 | | - return _innerStream.Seek(offset, origin); |
117 | | - } |
118 | | - |
119 | | - public override void SetLength(long value) |
120 | | - { |
121 | | - _innerStream.SetLength(value); |
122 | | - } |
123 | | - |
124 | | - public override void Write(byte[] buffer, int offset, int count) |
125 | | - { |
126 | | - throw new NotSupportedException("Synchronous operations not supported"); |
127 | | - } |
128 | | - |
129 | | - public override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken) |
130 | | - { |
131 | | - return _innerStream.CopyToAsync(destination, bufferSize, cancellationToken); |
132 | | - } |
133 | | - |
134 | | - public override Task FlushAsync(CancellationToken cancellationToken) |
135 | | - { |
136 | | - return _innerStream.FlushAsync(cancellationToken); |
137 | | - } |
138 | | - |
139 | | - public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) |
140 | | - { |
141 | | - return _innerStream.WriteAsync(buffer, offset, count, cancellationToken); |
142 | | - } |
143 | | - |
144 | | - public override ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, CancellationToken cancellationToken = default) |
145 | | - { |
146 | | - return _innerStream.WriteAsync(buffer, cancellationToken); |
147 | | - } |
148 | | - |
149 | | - public override ValueTask DisposeAsync() |
150 | | - { |
151 | | - return _innerStream.DisposeAsync(); |
152 | | - } |
153 | | - |
154 | | - public override bool CanRead => _innerStream.CanRead; |
155 | | - |
156 | | - public override bool CanSeek => _innerStream.CanSeek; |
157 | | - |
158 | | - public override bool CanWrite => _innerStream.CanWrite; |
159 | | - |
160 | | - public override long Length => _innerStream.Length; |
161 | | - |
162 | | - public override long Position |
163 | | - { |
164 | | - get => _innerStream.Position; |
165 | | - set => _innerStream.Position = value; |
166 | | - } |
167 | | - } |
168 | 54 | } |
169 | 55 | } |
0 commit comments