Класс ZipArchive требует потока, который предоставляет текущую позицию.Класс TrackablePositionStream
ниже сохраняет позицию, увеличивая поле при вызове записи
public class TrackablePositionStream : Stream
{
private readonly Stream _stream;
private long _position = 0;
public TrackablePositionStream(Stream stream)
{
this._stream = stream;
}
public override void Flush()
{
this._stream.Flush();
}
public override long Seek(long offset, SeekOrigin origin)
{
throw new NotImplementedException();
}
public override void SetLength(long value)
{
throw new NotImplementedException();
}
public override int Read(byte[] buffer, int offset, int count)
{
throw new NotImplementedException();
}
public override void Write(byte[] buffer, int offset, int count)
{
this._position += count;
this._stream.Write(buffer, offset, count);
}
public override bool CanRead => this._stream.CanRead;
public override bool CanSeek => this._stream.CanSeek;
public override bool CanWrite => this._stream.CanWrite;
public override long Length => this._stream.Length;
public override long Position
{
get
{
return this._position;
}
set
{
throw new NotImplementedException();
}
}
}
Затем используйте его в своем методе действия:
using( var archive = new ZipArchive(new TrackablePositionStream(response.OutputStream), ZipArchiveMode.Create, true ) )
{
var zipEntry = archive.CreateEntry( File );
using(var entryStream = zipEntry.Open() )
{
S3.StreamFile( File, Bucket ).CopyTo( entryStream );
}
}
return new EmptyResult();