protected override bool delete(string type, Stream stream, Func <string, bool> filter) { OutArchiveFormat archiveFormat = SevenZipWrapper.getArchiveFormat("abc" + type); Dictionary <int, string> fileDictionary = new Dictionary <int, string>(); foreach (var foundItem in lookup(getExtractor(stream, null), filter)) { fileDictionary.Add(foundItem.Value1, null); } if (fileDictionary.Count > 0) { string tempFile; using (var tempStream = TempStreamUtils.NewTempStream(out tempFile, "tmp")) StreamUtils.CopyStream(stream, tempStream, true, true, false); Delete(archiveFormat, tempFile, filter); using (var tempStream = new FileStream(tempFile, FileMode.Open)) StreamUtils.CopyStream(tempStream, stream, false, true, true); //SevenZipSharp crash when compressor.ModifyArchive() is used, //if Compression mode is Append (Create is fine). //lock (_lockObject) //{ // SevenZipCompressor compressor = getCompressor(archiveFormat); // compressor.ModifyArchive(archivePath, fileDictionary); //} } return(true); }
public bool Modify(string type, Stream stream, string orginalPath, string destName, bool isFolder, IProgress <FileExplorer.Defines.ProgressEventArgs> progress = null) { var arcFormat = getArchiveFormat("abc." + type); SevenZipCompressor compressor = getCompressor(arcFormat, null, progress); string tempFile = null; using (var tempStream = TempStreamUtils.NewTempStream(out tempFile, type)) StreamUtils.CopyStream(stream, tempStream, true, true, false); Modify(tempFile, orginalPath, destName, isFolder, progress); using (var tempStream = new FileStream(tempFile, FileMode.Open)) StreamUtils.CopyStream(tempStream, stream, false, true, true); return(true); }
//public void compressOne(string archivePath, string fileName, Stream fileStream) //{ // CompressMultiple(archivePath, new Dictionary<string, Stream>() { { fileName, fileStream } }); //} //public bool CompressOne(string type, Stream stream, string fileName, Stream fileStream) //{ // return CompressMultiple(type, stream, new Dictionary<string, Stream>() { { fileName, fileStream } }); //} protected override bool compressMultiple(string type, Stream stream, Dictionary <string, Stream> streamDic, IProgress <FileExplorer.Defines.ProgressEventArgs> progress = null) { var arcFormat = getArchiveFormat("abc." + type); SevenZipCompressor compressor = getCompressor(arcFormat, null, progress); //SevenZipSharp crash when compressor.CompressStreamDictionary() is used, //if Compression mode is Append (Create is fine). //lock (_lockObject) // compressor.CompressStreamDictionary(streamDic, container.Stream); string tempFile = null; using (var tempStream = TempStreamUtils.NewTempStream(out tempFile, type)) StreamUtils.CopyStream(stream, tempStream, true, true, false); CompressMultiple(tempFile, streamDic, progress); using (var tempStream = new FileStream(tempFile, FileMode.Open)) StreamUtils.CopyStream(tempStream, stream, false, true, true); return(true); }