Exemplo n.º 1
0
        /// <summary>
        /// Set the compression method to the best.
        /// </summary>
        public void SetBestCompression()
        {
            //Best method.
            PackCompression best  = (PackCompression)0;
            uint            least = uint.MaxValue;

            //Try each compression.
            foreach (var v in Enum.GetValues(typeof(PackCompression)))
            {
                CompressionMethod = (PackCompression)v;
                byte[] b = Write();
                if (b.Length < least)
                {
                    best  = CompressionMethod;
                    least = (uint)b.Length;
                }
            }

            //Set method.
            CompressionMethod = best;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Read the pack.
        /// </summary>
        /// <param name="r">The reader.</param>
        public override void Read(FileReader r)
        {
            //Try to reset stream.
            try {
                FileReader.BaseStream.Dispose();
                FileReader.Dispose();
            } catch { }

            //Read the data.
            r.ReadUInt32();
            CompressionMethod = (PackCompression)r.ReadUInt32();
            uint size = r.ReadUInt32();

            r.ReadUInt32();
            MemoryStream src = new MemoryStream(r.ReadBytes((int)size));
            MemoryStream o   = new MemoryStream();

            //Decompress data.
            switch (CompressionMethod)
            {
            case PackCompression.Gzip:
                GZip.Decompress(src, o, false);
                break;

            case PackCompression.Bzip2:
                BZip2.Decompress(src, o, false);
                break;

            case PackCompression.Lzma:
                byte[] lzmaTemp = LZMA.Engine.Decompress(src.ToArray());
                o.Write(lzmaTemp, 0, lzmaTemp.Length);
                break;
            }

            //Clean up.
            FileReader = new FileReader(o);
            src.Dispose();
        }