Exemplo n.º 1
0
        internal void CloseStream(MultipleSubStreamWriter multiSubStream)
        {
            if (_openStream != multiSubStream)
            {
                throw new InvalidOperationException();
            }

            _items.Add(multiSubStream.Header);

            _openStream = null;
        }
Exemplo 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);
        }