public object Clone() { var clone = new CompressedData() { Data = this.Data != null ? (byte[])this.Data.Clone() : null, }; clone._Blocks.AddRange(this._Blocks); return(clone); }
public static CompressedData Pack(Stream input) { var compressedData = new CompressedData(); using (var output = new MemoryStream()) { uint virtualOffset = 0; uint realOffset = 4; while (input.Position < input.Length) { var length = (uint)Math.Min(0x40000, input.Length - input.Position); using (var block = new MemoryStream()) { var zlib = new DeflaterOutputStream(block); //, new Deflater(9, false)); zlib.WriteFromStream(input, length); zlib.Finish(); compressedData.Blocks.Add(new Block() { VirtualOffset = virtualOffset, FileOffset = realOffset, IsCompressed = true, }); block.Position = 0; output.WriteFromStream(block, block.Length); realOffset += (uint)block.Length; } virtualOffset += length; } output.Position = 0; compressedData.Data = new byte[output.Length]; output.Read(compressedData.Data, 0, compressedData.Data.Length); compressedData.Blocks.Add(new Block() { VirtualOffset = virtualOffset, FileOffset = realOffset, IsCompressed = true, }); } return(compressedData); }
public void Deserialize(Stream input, Endian endian) { var baseOffset = input.Position; var magic = input.ReadValueU32(endian); if (magic != Signature) { throw new FormatException(); } this.Version = input.ReadValueU32(endian); if (this.Version != 1) { throw new FormatException(); } uint offsetData = input.ReadValueU32(endian); uint offsetHeader = input.ReadValueU32(endian); uint offsetDescriptor = input.ReadValueU32(endian); if (offsetData != 20) { throw new FormatException(); } this.Data = new CompressedData(); this.Data.Deserialize(input, endian); if (baseOffset + offsetHeader != input.Position) { throw new FormatException(); } this.Header = new CompressedData(); this.Header.Deserialize(input, endian); if (baseOffset + offsetDescriptor != input.Position) { throw new FormatException(); } this.Descriptor = new CompressedData(); this.Descriptor.Deserialize(input, endian); }