public void Write_Throws() { var block = new CompressedBlock(); Assert.Throws <NotImplementedException>(() => block.WriteTo(null, 0)); Assert.Throws <NotImplementedException>(() => block.Size); }
private static List <CompressedBlock> BlockCompress(IEnumerable <byte> data, int blockSize = 32768) { var parts = data.Clump(blockSize).Select(p => p.ToList()).ToList(); var outBlocks = new List <CompressedBlock>(); var uncompressedPos = 0; foreach (var part in parts) { var outBlock = new CompressedBlock { DataRaw = part.ToArray(), UPos = uncompressedPos, OutSize = part.Count }; var compData = new byte[part.Count * 2]; Compression.Compress(outBlock.DataRaw, ref compData); outBlock.DataComp = compData; outBlocks.Add(outBlock); uncompressedPos += outBlock.DataRaw.Length; } var blocksSorted = new List <CompressedBlock>(outBlocks.Count); if (blocksSorted.Count == 1) { blocksSorted.Add(outBlocks[0]); } else { blocksSorted.Add(outBlocks[1]); for (var i = 2; i < outBlocks.Count; i++) { blocksSorted.Add(outBlocks[i]); } blocksSorted.Add(outBlocks[0]); var compPos = 0; foreach (var outBlock in blocksSorted) { outBlock.CPos = compPos; if (outBlock.DataComp.Length % 4 != 0) { var tmpdc = outBlock.DataComp; Array.Resize(ref tmpdc, tmpdc.Length + (4 - tmpdc.Length % 4)); outBlock.DataComp = tmpdc; } compPos += outBlock.DataComp.Length + 24; } } return(blocksSorted); }
public void ReadFrom_Works() { var block = new CompressedBlock(); block.ReadFrom(File.ReadAllBytes("Dmg/compressedblock.bin"), 0); Assert.Equal(0u, block.BlocksDescriptor); Assert.Equal(2u, block.CheckSum.ChecksumSize); Assert.Equal("AAAAIEoNh3YAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=", Convert.ToBase64String(block.CheckSum.Data)); Assert.Equal(0x88, block.CheckSum.Size); Assert.Equal(0u, block.CheckSum.Type); Assert.Equal(0u, block.DataStart); Assert.Equal(0x802u, block.DecompressBufferRequested); Assert.Equal(0, block.FirstSector); Assert.Equal(1u, block.InfoVersion); Assert.Collection( block.Runs, r => { Assert.Equal(RunType.LzmaCompressed, r.Type); }, r => { Assert.Equal(RunType.Terminator, r.Type); }); Assert.Equal(1, block.SectorCount); Assert.Equal(0x6d697368u, block.Signature); }