The ZipArchive
can work with seekable streams only. But you can use e.g. MemoryStream
to prepare a ZIP archive in memory, then copy it to a non-seekable stream as follows:
MemoryStream ms = new MemoryStream();
// create ZipArchive in memory
// use LeaveOpen argument to keep MemoryStream usable after closing the ZipArchive
using (ZipArchive zip = new ZipArchive(ms, ArchiveStreamCloseMode.LeaveOpen))
{
// work with the ZipArchive ...
zip.Add("C:/temp/data");
}
// copy MemoryStream to any writable stream (not necessary seekable)
using (FileStream fs = new FileStream("C:/temp/data.zip", FileMode.Create))
{
ms.WriteTo(fs);
}