Exemple #1
0
        public Stream GetStream(FileEntry entry, bool newFileStream = false)
        {
            Stream stream;

            if (entry.cachedBytes != null)
            {
                stream = new MemoryStream(entry.cachedBytes);
            }
            else if (fileStream == null)
            {
                throw new IOException($"File not open: {path}");
            }
            else if (newFileStream)
            {
                var ers = new EntryReadStream(this, entry, File.OpenRead(path), false);
                independentEntryReadStreams.Add(ers);
                stream = ers;
            }
            else if (sharedEntryReadStream != null)
            {
                throw new IOException($"Previous entry read stream not closed: {sharedEntryReadStream.Name}");
            }
            else
            {
                stream = sharedEntryReadStream = new EntryReadStream(this, entry, fileStream, true);
            }

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

            return(stream);
        }
Exemple #2
0
 internal void OnStreamClosed(EntryReadStream stream)
 {
     if (stream == sharedEntryReadStream)
     {
         sharedEntryReadStream = null;
     }
     else if (!independentEntryReadStreams.Remove(stream))
     {
         throw new IOException($"Closed EntryReadStream not associated with this file. {stream.Name} @ {path}");
     }
 }