ICSharpCode.SharpZipLib.Zip.ZipFile.GetInputStream C# (CSharp) Method

GetInputStream() public method

Creates an input stream reading a zip entry
/// The ZipFile has already been closed /// /// The compression method for the entry is unknown /// /// The entry is not found in the ZipFile ///
public GetInputStream ( long entryIndex ) : Stream
entryIndex long The index of the entry to obtain an input stream for.
return Stream
        public Stream GetInputStream(long entryIndex) {
            if (isDisposed_) {
                throw new ObjectDisposedException("ZipFile");
            }

            long start=LocateEntry(entries_[entryIndex]);
            CompressionMethod method=entries_[entryIndex].CompressionMethod;
            Stream result=new PartialInputStream(this, start, entries_[entryIndex].CompressedSize);

            if (entries_[entryIndex].IsCrypted) {
                result=CreateAndInitDecryptionStream(result, entries_[entryIndex]);
                if (result==null) {
                    throw new ZipException("Unable to decrypt this entry");
                }
            }

            switch (method) {
                case CompressionMethod.Stored:
                    // read as is.
                    break;

                case CompressionMethod.Deflated:
                    // No need to worry about ownership and closing as underlying stream close does nothing.
                    result=new InflaterInputStream(result, new Inflater(true));
                    break;

                default:
                    throw new ZipException("Unsupported compression method "+method);
            }

            return result;
        }

Same methods

ZipFile::GetInputStream ( ZipEntry entry ) : Stream

Usage Example

Esempio n. 1
0
        public void Convert(EndianBinaryWriter writer)
        {
            var jbtWriter = new JbtWriter(writer);

            var zf = new ZipFile(jarFile);

            foreach (ZipEntry ze in zf)
            {
                if (!ze.IsFile) continue;
                if (!ze.Name.EndsWith(".class")) continue;

                var type = new CompileTypeInfo();

                type.Read(zf.GetInputStream(ze));

                var reader = new BinaryReader(zf.GetInputStream(ze));

                var buffer = new byte[ze.Size];
                reader.Read(buffer, 0, (int)ze.Size);

                jbtWriter.Write(type.Name, buffer);
            }

            jbtWriter.Flush();
        }
All Usage Examples Of ICSharpCode.SharpZipLib.Zip.ZipFile::GetInputStream