Beispiel #1
0
        private Stream GetStream(FileEntry entry)
        {
            Stream stream;

            if (entry.cachedBytes != null)
            {
                stream = new MemoryStream(entry.cachedBytes);
            }
            else
            {
                if (fileStream == null)
                {
                    throw new IOException("File not open: " + path);
                }
                if (lastEntryReadStream != null && !lastEntryReadStream.IsDisposed)
                {
                    throw new IOException($"Previous entry read stream not closed: {lastEntryReadStream.name}");
                }

                stream = lastEntryReadStream = new EntryReadStream(fileStream, entry.offset, entry.compressedSize, entry.name);
            }

            if (entry.compressedSize != entry.size)
            {
                stream = new DeflateStream(stream, CompressionMode.Decompress);
            }

            return(stream);
        }
Beispiel #2
0
        public Stream GetStream(FileEntry entry, bool newFileStream = false)
        {
            Stream stream;

            if (entry.cachedBytes != null)
            {
                stream = new MemoryStream(entry.cachedBytes);
            }
            else if (newFileStream)
            {
                // File.OpenRead is fine, it uses FindFirstFile which is case insensitive
                stream = new EntryReadStream(File.OpenRead(path), entry, false);
            }
            else
            {
                if (fileStream == null)
                {
                    throw new IOException($"File not open: {path}");
                }

                if (lastEntryReadStream != null && !lastEntryReadStream.IsClosed)
                {
                    throw new IOException($"Previous entry read stream not closed: {lastEntryReadStream.Name}");
                }

                stream = lastEntryReadStream = new EntryReadStream(fileStream, entry, true);
            }

            if (entry.IsCompressed)
            {
                stream = new DeflateStream(stream, CompressionMode.Decompress);
            }

            return(stream);
        }