void StreamCompressedContent(IO.EndianStream s)
        {
            if (s.IsReading)
            {
                using (var cs = new CompressedStream(true))
                {
                    Stream(s, EnumFlags.Test(Flags, FileFlags.EncryptContent), cs,
                           userKey: Header.DataCryptKey, streamLeftovers: StreamLeftovers);

                    cs.Decompress();
                    Content = cs.UncompressedData;
                }
            }
            else if (s.IsWriting)
            {
                using (var cs = new CompressedStream(true))
                    using (var ms = new System.IO.MemoryStream(kMaxContentSize))
                        using (var sout = new IO.EndianWriter(ms, s.ByteOrder))
                        {
                            sout.Write(Content);
                            sout.Seek(0);

                            cs.InitializeFromStream(ms);
                            cs.Compress();

                            Stream(s, EnumFlags.Test(Flags, FileFlags.EncryptContent), cs,
                                   userKey: Header.DataCryptKey, streamLeftovers: StreamLeftovers);
                        }
            }
        }
        public void Read(IO.EndianReader s)
        {
            s.Owner = this;

            Flags   = s.Read(FileFlagsStreamer.Instance);
            Version = s.ReadUInt16();
            if (Version != kVersion)
            {
                throw new IO.VersionMismatchException(s.BaseStream,
                                                      kVersion, Version);
            }

            Read(s, EnumFlags.Test(Flags, FileFlags.EncryptHeader), Header, MediaHeader.kSizeOf);
            GenerateHash();

            if (EnumFlags.Test(Flags, FileFlags.CompressContent))
            {
                using (var cs = new CompressedStream(true))
                {
                    Read(s, EnumFlags.Test(Flags, FileFlags.EncryptContent), cs,
                         userKey: Header.DataCryptKey, readLeftovers: ReadLeftovers);

                    cs.Decompress();
                    Content = cs.UncompressedData;
                }
            }
            else
            {
                Content = s.ReadBytes((int)(s.BaseStream.Length - s.BaseStream.Position));
            }
        }
        public static byte[] DecompressFromStream(IO.EndianStream blockStream)
        {
            Contract.Requires <ArgumentNullException>(blockStream != null);
            Contract.Ensures(Contract.Result <byte[]>() != null);

            byte[] buffer;
            using (var cs = new CompressedStream())
            {
                cs.Serialize(blockStream);
                cs.Decompress();
                buffer = cs.UncompressedData;
            }

            return(buffer);
        }