コード例 #1
0
ファイル: PackedFile.cs プロジェクト: yungshing/War3Net
        private static MemoryStream Decompress(BinaryReader reader, PackedFileHeader header)
        {
            var blockCount       = header.DataBlocksCount;
            var decompressedSize = header.DecompressedSize;
            var isReforged       = header.IsReforgedReplay;

            var decompressedData = new MemoryStream();

            for (var chunk = 0; chunk < blockCount; chunk++)
            {
                var compressedChunkSize = reader.ReadUInt16();
                if (isReforged)
                {
                    reader.BaseStream.Seek(2, SeekOrigin.Current);
                }

                var decompressedChunkSize = reader.ReadUInt16();
                var checksum = reader.ReadUInt32();
                if (isReforged)
                {
                    reader.BaseStream.Seek(2, SeekOrigin.Current);
                }

                using var compressedDataStream = new MemoryStream();
                reader.BaseStream.CopyTo(compressedDataStream, compressedChunkSize, StreamExtensions.DefaultBufferSize);
                compressedDataStream.Position = 0;

                var decompressedDataBytes  = ZLibCompression.Decompress(compressedDataStream, decompressedChunkSize);
                var decompressedDataLength = (chunk + 1 == blockCount) ? (int)(decompressedSize - decompressedData.Length) : decompressedChunkSize;
                decompressedData.Write(decompressedDataBytes, 0, decompressedDataLength);
            }

            decompressedData.Position = 0;
            return(decompressedData);
        }
コード例 #2
0
        public void CompressAndDecompressTest()
        {
            String reference = "Hello World 0123456789";

            byte[]          dataToCompress  = Encoding.Unicode.GetBytes(reference);
            ZLibCompression zLibCompression = new ZLibCompression();

            var compressed   = zLibCompression.Compress(dataToCompress);
            var decompressed = zLibCompression.Decompress(compressed);

            Assert.Equal(reference, Encoding.Unicode.GetString(decompressed));
        }
コード例 #3
0
        private Stream Decompress(BinaryReader reader)
        {
            var decompressedData = new MemoryStream();

            for (var chunk = 0; chunk < _header.DataBlocksCount; chunk++)
            {
                var compressedChunkSize   = reader.ReadUInt16();
                var decompressedChunkSize = reader.ReadUInt16();
                var checksum = reader.ReadUInt32();

                using var compressedDataStream = new MemoryStream();
                reader.BaseStream.CopyTo(compressedDataStream, compressedChunkSize, StreamExtensions.DefaultBufferSize);
                compressedDataStream.Position = 0;

                var decompressedDataBytes = ZLibCompression.Decompress(compressedDataStream, decompressedChunkSize);
                decompressedData.Write(decompressedDataBytes, 0, decompressedDataBytes.Length);
            }

            return(decompressedData);
        }