public static FCXCompressedData Pack(BinaryStream stream) { var compressedData = new FCXCompressedData(); using (var bs = new BinaryStream(1024)) { uint virtualOffset = 0; uint realOffset = 4; while (stream.Position < stream.Length) { var length = (int)Math.Min(0x40000, (stream.Length - stream.Position)); using (var block = new BinaryStream(16)) { var zlib = new DeflaterOutputStream(block); var buffer = stream.ReadBytes(length); zlib.Write(buffer, 0, length); zlib.Finish(); compressedData.Blocks.Add(new Block() { VirtualOffset = virtualOffset, FileOffset = realOffset, IsCompressed = true, }); block.Position = 0; block.CopyTo(bs); realOffset += (uint)block.Length; } virtualOffset += (uint)length; } compressedData.Data = bs.ToArray(); compressedData.Blocks.Add(new Block() { VirtualOffset = virtualOffset, FileOffset = realOffset, IsCompressed = true, }); } return(compressedData); }