コード例 #1
0
        public static void CompressFromStream(IO.EndianWriter blockStream, System.IO.Stream source,
                                              out uint streamAdler, out int streamSize)
        {
            Contract.Requires <ArgumentNullException>(blockStream != null);
            Contract.Requires <ArgumentNullException>(source != null);

            using (var ms = new System.IO.MemoryStream((int)source.Length + Header.kSizeOf))
                using (var s = new IO.EndianStream(ms, Shell.EndianFormat.Big, permissions: FA.Write))
                    using (var cs = new CompressedStream())
                    {
                        s.StreamMode = FA.Write;

                        cs.InitializeFromStream(source);
                        cs.Compress();

                        cs.Serialize(s);

                        ms.Position = 0;
                        streamSize  = (int)ms.Length;
                        streamAdler = Adler32.Compute(ms, streamSize);

                        ms.WriteTo(blockStream.BaseStream);
                    }
        }