Ejemplo n.º 1
0
        /// <summary>
        /// Gets the next stream.
        /// </summary>
        /// <returns>The next substream</returns>
        /// <exception cref="InvalidOperationException">The previous stream is still open</exception>
        public Stream GetNextStream()
        {
            if (_openReader != null)
            {
                throw new InvalidOperationException();
            }
            else if (_next >= _items.Count)
            {
                return(null);
            }

            MultiStreamItemHeader   header = _items[_next++];
            MultipleSubStreamReader reader = new MultipleSubStreamReader(this, BaseStream, header);
            Stream s = reader;

            if (0 != (header.ItemType & MultiStreamItemHeader.AssuredFlag))
            {
                s = new AssuredSubStream(s, _verificationMode);
            }

            if (0 != (header.ItemType & MultiStreamItemHeader.ZippedFlag))
            {
                s = new ZLibSubStream(s, System.IO.Compression.CompressionMode.Decompress);
            }

            _openReader = reader;
            return(s);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates the stream.
        /// </summary>
        /// <param name="args">The args.</param>
        /// <returns></returns>
        public Stream CreateStream(MultipleStreamArgs args)
        {
            if (_openStream != null)
            {
                throw new InvalidOperationException("Only one substream can be open at a time");
            }
            else if (args == null)
            {
                throw new ArgumentNullException("args");
            }

            if (_items.Count == _maxCount)
            {
                // TODO: Implement end header support
                throw new InvalidOperationException("Can't create any more substreams");
            }
            MultiStreamItemHeader header = new MultiStreamItemHeader();

            header.Offset   = BaseStream.Position = BaseStream.Length;
            header.ItemType = args.StreamType << 4;
            _updated        = true;

            MultipleSubStreamWriter innerStream = new MultipleSubStreamWriter(this, BaseStream, header);
            Stream result = innerStream;

            if (args.Assured)
            {
                result           = new AssuredSubStream(result, VerificationMode.Full);
                header.ItemType |= MultiStreamItemHeader.AssuredFlag;
            }

            if (args.GZipped)
            {
                result           = new ZLibSubStream(result, CompressionMode.Compress);
                header.ItemType |= MultiStreamItemHeader.ZippedFlag;
            }

            _openStream = innerStream;
            return(result);
        }