c# - Appending Streams with SevenSharpZip -
i've been knocking head on 2 days. we're using 7zipsharp create .7z files several source files (incoming emails in fact).
in order optimize application, want avoid hard disk access switched compressstreams function family.
the code using filenames instead of streams works perfectly. when switching streams, "keynotfoundexception", when compressionmode = append.
my test code:
for (var = 0; < numfiles; i++) { //if(i > 0) // compressor.compressionmode = compressionmode.append; console.writeline("adding copy num " + (i + 1) + " archive"); sevenziputil.addstream(file.openread(samplefile), "email-" + + ".eml", outfile); }
helper method code:
public static void addstream(stream instream, string filename, string destinationfile) { sevenzipcompressor comp = new sevenzipcompressor(); comp.archiveformat = outarchiveformat.sevenzip; comp.compressionlevel = compressionlevel.ultra; if(file.exists(destinationfile)) { comp.compressionmode = compressionmode.append; } filestream outstream = file.openwrite(destinationfile); comp.defaultitemname = filename; comp.compressstream(instream, outstream); outstream.flush(); outstream.close(); }
error source file librarymanager.cs, method inarchive, line 428.
if (_inarchives[user][format] == null
to summarize:
- appending files instead of streams, ok
- compressstream in mode = create, ok
- afterwards, compressstream in mode = append fails.
has working code of adding several streams .7z file, or may bug should post sevenzipsharp forum?
thanks,
would compressstreamdictionary work you?
void testzipping() { sevenzipcompressor compressor = new sevenzipcompressor { archiveformat = outarchiveformat.sevenzip, compressionlevel = compressionlevel.ultra, }; using (stream output = file.open("test.7z", filemode.createnew)) using (stream file1 = file.open("test1.txt", filemode.open)) using (stream file2 = file.open("test2.txt", filemode.open)) { compressor.compressstreamdictionary(new dictionary<string, stream> {{ "test1.txt", file1 }, { "test2.txt", file2 }}, output); } }
i suspect way trying creating several complete archives consecutively in 1 stream, rather appending files single archive. though might due lack of resource management (you should wrapping lifetime of streams in using blocks, or otherwise disposing of them properly).
Comments
Post a Comment