-
Notifications
You must be signed in to change notification settings - Fork 976
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to stream Zip File in controller's Response.Body #731
Comments
Yeah, this was overlooked when implementing the async solution... class StreamWrapper: Stream
{
{
Stream _innerStream;
public StreamWrapper(Stream innerStream)
{
_innerStream = innerStream;
}
public override bool CanRead => _innerStream.CanRead;
public override bool CanSeek => _innerStream.CanSeek;
public override bool CanWrite => _innerStream.CanWrite;
public override void Flush() => _innerStream.Flush();
public override Task FlushAsync(CancellationToken ct) => _innerStream.FlushAsync(ct);
public override long Length => _innerStream.Length;
public override long Position
{
get => 0;
set => _innerStream.Position = value;
}
public override int Read(byte[] buffer, int offset, int count) => _innerStream.Read(buffer, offset, count);
public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken ct) => _innerStream.ReadAsync(buffer, offset, count, ct);
public override long Seek(long offset, SeekOrigin origin) => _innerStream.Seek(offset, origin);
public override void SetLength(long value) => _innerStream.SetLength(value);
public override void Write(byte[] buffer, int offset, int count) => _innerStream.Write(buffer, offset, count);
public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken ct) => _innerStream.WriteAsync(buffer, offset, count, ct);
} and wrapping await using (var stream = new ZipOutputStream(new StreamWrapper(context.Response.Body))) |
Thanks for the workaround ! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Steps to reproduce
new ZipOutputStream(context.Response.Body)
andPutNextEntryAsync()
Expected behavior
the zip file can be sent streamingly to the client by writing directily to context.Response.Body, without creating an intermediary MemoryStream.
The reason for not using a MemoryStream and writing directly to context.Response.Bodyis to prevent high memory consumption on the server when creating big zip files. I haven't found any library that can handle this correctly, except SharpZipLib which seems to be really closed to achieve this 😥
Actual behavior
when calling stream.PutNextEntryAsync(), a "System.NotSupportedException: Specified method is not supported" is thrown., complete stacktrace :
Version of SharpZipLib
Obtained from (only keep the relevant lines)
full sample to reproduce (must create a .net 6 project) :
The text was updated successfully, but these errors were encountered: