Build archive in memorystream while keeping it open #130

Open
opened 2026-01-29 22:07:07 +00:00 by claunia · 0 comments
Owner

Originally created by @zaryk on GitHub (Sep 27, 2016).

Is there a way to build archive in memorystream while keeping it open? The below way seems to create it, but once returned, it is not open. I also looked at the ZipArchive constructor where there is an option to keep it open, but passing in the stream said that it could not find zip headers. I just need a regular zip. I know the supported formats for streams are the below, so does that mean this will not work?

BZip2Stream Both
GZipStream Both
DeflateStream Both
LZMAStream Both
PPMdStream Both

internal virtual MemoryStream InternalDownloadStream(int offset, int readSize) { var archive = ZipArchive.Create(); archive.AddAllFromDirectory(directoryInfo.FullName, "*.*", SearchOption.AllDirectories); var stream = new MemoryStream(); if (offset == 0 && readSize == 0) { archive.SaveTo(stream, new CompressionInfo() { DeflateCompressionLevel = Core.SharpCompress.Compressor.Deflate.CompressionLevel.Default, Type = CompressionType.None }); return stream; } else { throw new NotImplementedException(); } }

Originally created by @zaryk on GitHub (Sep 27, 2016). Is there a way to build archive in memorystream while keeping it open? The below way seems to create it, but once returned, it is not open. I also looked at the ZipArchive constructor where there is an option to keep it open, but passing in the stream said that it could not find zip headers. I just need a regular zip. I know the supported formats for streams are the below, so does that mean this will not work? BZip2Stream Both GZipStream Both DeflateStream Both LZMAStream Both PPMdStream Both ` internal virtual MemoryStream InternalDownloadStream(int offset, int readSize) { var archive = ZipArchive.Create(); archive.AddAllFromDirectory(directoryInfo.FullName, "*.*", SearchOption.AllDirectories); var stream = new MemoryStream(); if (offset == 0 && readSize == 0) { archive.SaveTo(stream, new CompressionInfo() { DeflateCompressionLevel = Core.SharpCompress.Compressor.Deflate.CompressionLevel.Default, Type = CompressionType.None }); return stream; } else { throw new NotImplementedException(); } } `
claunia added the question label 2026-01-29 22:07:07 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#130