public IExtractor ExtractFile(ulong index, string outputDirectory) { if (index >= (ulong)_Files.LongLength) { throw new ArgumentOutOfRangeException($"Index `{index}` is out of range."); } SevenZipArchiveFile file = _Files[index]; if (!preProcessFile(outputDirectory, file)) { string fullPath = Path.Combine(outputDirectory, PreserveDirectoryStructure ? file.Name : Path.GetFileName(file.Name)); // progress provider SevenZipProgressProvider szpp = null; if (ProgressDelegate != null) { szpp = new SevenZipProgressProvider(_Files, new[] { index }, ProgressDelegate); } // extraction //Trace.TraceInformation($"Filename: `{file.Name}`, file size: `{file.Size} bytes`."); var sx = new SevenZipStreamsExtractor(stream, header.RawHeader.MainStreamsInfo, Password); using (Stream fileStream = File.Create(fullPath)) sx.Extract((ulong)file.UnPackIndex, fileStream, szpp); if (file.Time != null) { File.SetLastWriteTimeUtc(fullPath, (DateTime)file.Time); } } return(this); }
public IExtractor ExtractFile(ulong index, Stream outputStream) { if (index >= (ulong)_Files.LongLength) { throw new ArgumentOutOfRangeException($"Index `{index}` is out of range."); } if (outputStream == null || !outputStream.CanWrite) { throw new ArgumentException($"Stream `{nameof(outputStream)}` is invalid or cannot be written to."); } SevenZipArchiveFile file = _Files[index]; if (file.IsEmpty) { //Trace.TraceWarning($"Filename: {file.Name} is a directory, empty file or anti file, nothing to output to stream."); } else { // progress provider SevenZipProgressProvider szpp = null; if (ProgressDelegate != null) { szpp = new SevenZipProgressProvider(_Files, new[] { index }, ProgressDelegate); } // extraction //Trace.TraceInformation($"Filename: `{file.Name}`, file size: `{file.Size} bytes`."); //Trace.TraceInformation("Extracting..."); var sx = new SevenZipStreamsExtractor(stream, header.RawHeader.MainStreamsInfo, Password); sx.Extract((ulong)file.UnPackIndex, outputStream, szpp); } return(this); }