mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-02-08 05:27:04 +00:00
Build archive in memorystream while keeping it open #133
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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(); } }@adamhathcock commented on GitHub (Sep 28, 2016):
You mean you want an option on the 'SaveTo' method on WritableArchives to leave the stream open?
@adamhathcock commented on GitHub (Sep 28, 2016):
Also, you need to reset the
MemoryStreamposition back to 0 to make it usable too.@zaryk commented on GitHub (Sep 28, 2016):
I suppose. It doesn't really matter where.
I am sure I tried that as well, but maybe not. Will get back to you. Setting position immediately after SaveTo, before return, I get the same thing, "cannot access a closed stream".
@adamhathcock commented on GitHub (Sep 29, 2016):
I thought the options got passed down. Anyway, I've just refactored the way options work for the next release. Maybe it will be more clear.
@adamhathcock commented on GitHub (Sep 29, 2016):
https://github.com/adamhathcock/sharpcompress/blob/master/USAGE.md#create-zip-archive-from-all-files-in-a-directory-and-save-in-memory
@zaryk commented on GitHub (Sep 29, 2016):
cool thanks! I will check it out.