public static void WriteTo(this IArchiveEntry archiveEntry, Stream streamToWriteTo)
        {
            if (archiveEntry.Archive.Type == ArchiveType.Rar && archiveEntry.Archive.IsSolid)
            {
                throw new InvalidFormatException("Cannot use Archive random access on SOLID Rar files.");
            }

            if (archiveEntry.IsDirectory)
            {
                throw new ExtractionException("Entry is a file directory and cannot be extracted.");
            }

            var streamListener = archiveEntry.Archive as IArchiveExtractionListener;

            streamListener.EnsureEntriesLoaded();
            streamListener.FireEntryExtractionBegin(archiveEntry);
            streamListener.FireFilePartExtractionBegin(archiveEntry.Key, archiveEntry.Size, archiveEntry.CompressedSize);
            var entryStream = archiveEntry.OpenEntryStream();

            if (entryStream == null)
            {
                return;
            }
            using (entryStream)
                using (Stream s = new ListeningStream(streamListener, entryStream))
                {
                    s.TransferTo(streamToWriteTo);
                }
            streamListener.FireEntryExtractionEnd(archiveEntry);
        }
        public static void WriteTo(this IArchiveEntry archiveEntry, Stream streamToWriteTo)
        {
            if (archiveEntry.IsDirectory)
            {
                throw new ExtractionException("Entry is a file directory and cannot be extracted.");
            }

            var streamListener = (IArchiveExtractionListener)archiveEntry.Archive;

            streamListener.EnsureEntriesLoaded();
            streamListener.FireEntryExtractionBegin(archiveEntry);
            streamListener.FireFilePartExtractionBegin(archiveEntry.Key, archiveEntry.Size, archiveEntry.CompressedSize);
            var entryStream = archiveEntry.OpenEntryStream();

            if (entryStream is null)
            {
                return;
            }
            using (entryStream)
            {
                using (Stream s = new ListeningStream(streamListener, entryStream))
                {
                    s.TransferTo(streamToWriteTo);
                }
            }
            streamListener.FireEntryExtractionEnd(archiveEntry);
        }
        public static void WriteTo(IArchiveEntry archiveEntry, Stream streamToWriteTo)
        {
            if ((archiveEntry.Archive.Type == ArchiveType.Rar) && archiveEntry.Archive.IsSolid)
            {
                throw new InvalidFormatException("Cannot use Archive random access on SOLID Rar files.");
            }
            if (archiveEntry.IsDirectory)
            {
                throw new ExtractionException("Entry is a file directory and cannot be extracted.");
            }
            IArchiveExtractionListener archive = archiveEntry.Archive as IArchiveExtractionListener;

            archive.EnsureEntriesLoaded();
            archive.FireEntryExtractionBegin(archiveEntry);
            archive.FireFilePartExtractionBegin(archiveEntry.Key, archiveEntry.Size, archiveEntry.CompressedSize);
            Stream stream = archiveEntry.OpenEntryStream();

            if (stream != null)
            {
                using (stream)
                {
                    using (Stream stream2 = new ListeningStream(archive, stream))
                    {
                        Utility.TransferTo(stream2, streamToWriteTo);
                    }
                }
                archive.FireEntryExtractionEnd(archiveEntry);
            }
        }
示例#4
0
 internal static void Extract <TEntry, TVolume>(this TEntry entry, AbstractArchive <TEntry, TVolume> archive, Stream streamToWriteTo) where TEntry : IArchiveEntry where TVolume : IVolume
 {
     if (entry.IsDirectory)
     {
         throw new ExtractionException("Entry is a file directory and cannot be extracted.");
     }
     archive.EnsureEntriesLoaded();
     archive.FireEntryExtractionBegin(entry);
     archive.FireFilePartExtractionBegin(entry.FilePath, entry.Size, entry.CompressedSize);
     using (Stream stream = new ListeningStream(archive, entry.OpenEntryStream()))
     {
         stream.TransferTo(streamToWriteTo);
     }
     archive.FireEntryExtractionEnd(entry);
 }