SevenZip/SevenZipExtractor.cs
/// <summary>
///   Unpacks the file by its index to the specified stream.
/// </summary>
/// <param name = "index">Index in the archive file table.</param>
/// <param name = "stream">The stream where the file is to be unpacked.</param>
Unpacks the file by its index to the specified stream.
Unpacks the file by its index to the specified stream .
public void ExtractFile(int index, Stream stream)
        {
            DisposedCheck();
            ClearExceptions();
            if (!CheckIndexes(index))
            {
                if (!ThrowException(null, new ArgumentException("The index must be more or equal to zero.", "index")))
                {
                    return;
                }
            }
            if (!stream.CanWrite)
            {
                if (!ThrowException(null, new ArgumentException("The specified stream can not be written.", "stream")))
                {
                    return;
                }
            }
            InitArchiveFileData(false);
            if (index > _filesCount - 1)
            {
                if (!ThrowException(null, new ArgumentOutOfRangeException(
                                              "index", "The specified index is greater than the archive files count.")))
                {
                    return;
                }
            }
            var indexes = new[] {(uint) index};
            if (_isSolid.Value)
            {
                indexes = SolidIndexes(indexes);
            }
            IInStream archiveStream = GetArchiveStream(false);
            ArchiveOpenCallback openCallback = GetArchiveOpenCallback();
            if (!OpenArchive(archiveStream, openCallback))
            {
                return;
            }
            try
            {
                using (ArchiveExtractCallback aec = GetArchiveExtractCallback(stream, (uint) index, indexes.Length))
                {
                    try
                    {
                        CheckedExecute(
                            _archive.Extract(indexes, (uint) indexes.Length, 0, aec),
                            SevenZipExtractionFailedException.DEFAULT_MESSAGE, aec);
                    }
                    finally
                    {
                        FreeArchiveExtractCallback(aec);
                    }
                }
            }
            catch (Exception)
            {
                if (openCallback.ThrowException())
                {
                    throw;
                }
            }
            OnEvent(ExtractionFinished, EventArgs.Empty, false);
            ThrowUserException();
        }
public void ExtractFile ( int index , Stream stream ) { DisposedCheck ( ) ; ClearExceptions ( ) ; if ( ! CheckIndexes ( index ) ) { if ( ! ThrowException ( null , new ArgumentException ( " " , " " ) ) ) { return ; } } if ( ! stream . CanWrite ) { if ( ! ThrowException ( null , new ArgumentException ( " " , " " ) ) ) { return ; } } InitArchiveFileData ( false ) ; if ( index > _filesCount - 1 ) { if ( ! ThrowException ( null , new ArgumentOutOfRangeException ( " " , " " ) ) ) { return ; } } var indexes = new [ ] { ( uint ) index } ; if ( _isSolid . Value ) { indexes = SolidIndexes ( indexes ) ; } IInStream archiveStream = GetArchiveStream ( false ) ; ArchiveOpenCallback openCallback = GetArchiveOpenCallback ( ) ; if ( ! OpenArchive ( archiveStream , openCallback ) ) { return ; } try { using ( ArchiveExtractCallback aec = GetArchiveExtractCallback ( stream , ( uint ) index , indexes . Length ) ) { try { CheckedExecute ( _archive . Extract ( indexes , ( uint ) indexes . Length , 0 , aec ) , SevenZipExtractionFailedException . DEFAULT_MESSAGE , aec ) ; } finally { FreeArchiveExtractCallback ( aec ) ; } } } catch ( Exception ) { if ( openCallback . ThrowException ( ) ) { throw ; } } OnEvent ( ExtractionFinished , EventArgs . Empty , false ) ; ThrowUserException ( ) ; }
Unpacks the file by its index to the specified stream.
Unpacks the file by its index to the specified stream .
index
int
Index in the archive file table.
Index in the archive file table .
stream
Stream
The stream where the file is to be unpacked.
The stream where the file is to be unpacked .