public void DecompressInvalidArgumentsTest(int offset, int length, int decompressedOffset, int decompressedLength) { byte[] buffer = new byte[1024]; byte[] decompressedBuffer = new byte[1024]; Assert.Throws <ArgumentOutOfRangeException>(() => LzfseCompressor.Decompress(buffer, offset, length, decompressedBuffer, decompressedOffset, decompressedLength)); }
public void DecompressNullTest() { byte[] buffer = Array.Empty <byte>(); Assert.Throws <ArgumentNullException>(() => LzfseCompressor.Decompress(buffer, null)); Assert.Throws <ArgumentNullException>(() => LzfseCompressor.Decompress(null, buffer)); Assert.Throws <ArgumentNullException>(() => LzfseCompressor.Decompress(buffer, 0, 0, null, 0, 0)); Assert.Throws <ArgumentNullException>(() => LzfseCompressor.Decompress(null, 0, 0, buffer, 0, 0)); }
public void RoundtripTest() { byte[] buffer = Encoding.UTF8.GetBytes("Hello, World!"); byte[] compressedBuffer = new byte[1024]; byte[] decompressedBuffer = new byte[1024]; Assert.NotEqual(0, LzfseCompressor.Compress(buffer, compressedBuffer)); Assert.Equal(buffer.Length, LzfseCompressor.Decompress(compressedBuffer, decompressedBuffer)); Assert.Equal("Hello, World!", Encoding.UTF8.GetString(decompressedBuffer, 0, buffer.Length)); }
/// <summary> /// The main entrypoint. /// </summary> /// <param name="args"> /// Command-line arguments /// </param> public static void Main(string[] args) { byte[] buffer = Encoding.UTF8.GetBytes("Hello, World!"); byte[] compressedBuffer = new byte[1024]; byte[] decompressedBuffer = new byte[1024]; LzfseCompressor.Compress(buffer, compressedBuffer); int length = LzfseCompressor.Decompress(compressedBuffer, decompressedBuffer); Console.WriteLine(Encoding.UTF8.GetString(decompressedBuffer, 0, length)); }
/// <summary> /// Initializes a new instance of the <see cref="BTreeNodeTests"/> class. /// </summary> public BTreeNodeTests() { var data = new byte[0x1000]; LzfseCompressor.Decompress( Convert.FromBase64String("YnZ4MgAQAAAoAOAAAAkAECj92IkRFQAQnwAAABVcAAhn5xuAvQFgAxuA/QUAAMA+ex8+BIAPgScAgCcAAAAAAAAAAAAAAACAv/A3+A" + "1egBfgBQB4AYAX4AV4AQAAAAAAAAAAAAAAAAAAAIAXAAAAAAAAAAAAAHgBXgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA+BrgBQAAAJybRYhvkHVluTVKA" + "gEAAAAAAAAAAACPjP9nCxT9ouKyfQFidngk"), data); this.buffer.Write(0, data, 0, data.Length); var nodeData = new byte[0x1000]; LzfseCompressor.Decompress( Convert.FromBase64String("YnZ4MgAQAAAwABABAAcAIO352ciiEQBwmQAAABiU8Am3FwBcAKcAF8AFcHFxwQUAANx+FR8DAPANfAMAAAAAAAAAAAAAAAAA/JDX19" + "fX11zDNfATAAAAANcAAADANQBcAwBcAwAAAABwDQDXAMA1wDUAAAAAAAAAAAAAAAAAXAMAAAAAAAAAAAAA1wAAAAAAAAAAAAAAAHANAA7JOpEyn85v7ZpAoN03DwUAA" + "AAAAAAAAOBS7/+VYMAs6WJ2eCQ="), nodeData); this.buffer.Write(3 * nodeData.Length, nodeData, 0, nodeData.Length); }
private void LoadRun(CompressedRun run) { int toCopy = (int)(run.SectorCount * Sizes.Sector); switch (run.Type) { case RunType.ZlibCompressed: this.stream.Position = run.CompOffset + 2; // 2 byte zlib header using (DeflateStream ds = new DeflateStream(this.stream, CompressionMode.Decompress, true)) { StreamUtilities.ReadExact(ds, this.decompBuffer, 0, toCopy); } break; case RunType.AdcCompressed: this.stream.Position = run.CompOffset; byte[] compressed = StreamUtilities.ReadExact(this.stream, (int)run.CompLength); if (ADCDecompress(compressed, 0, compressed.Length, this.decompBuffer, 0) != toCopy) { throw new InvalidDataException("Run too short when decompressed"); } break; case RunType.BZlibCompressed: using ( BZip2DecoderStream ds = new BZip2DecoderStream( new SubStream( this.stream, run.CompOffset, run.CompLength), Ownership.None)) { StreamUtilities.ReadExact(ds, this.decompBuffer, 0, toCopy); } break; case RunType.LzfseCompressed: this.stream.Position = run.CompOffset; byte[] lzfseCompressed = StreamUtilities.ReadExact(this.stream, (int)run.CompLength); if (LzfseCompressor.Decompress(lzfseCompressed, this.decompBuffer) != toCopy) { throw new InvalidDataException("Run too short when decompressed"); } break; case RunType.LzmaCompressed: using (var ds = new XZInputStream( new SubStream( this.stream, run.CompOffset, run.CompLength))) { StreamUtilities.ReadExact(ds, this.decompBuffer, 0, toCopy); } break; case RunType.Zeros: case RunType.Raw: case RunType.None: break; default: throw new NotImplementedException("Unrecognized run type " + run.Type); } this.activeRun = run; }