public void TestInvalidBlockCrcStream() { BZip2DecoderStream decoder = new BZip2DecoderStream(new MemoryStream(InvalidBlockCrcData), Ownership.Dispose); byte[] buffer = new byte[1024]; Assert.Throws <InvalidDataException>(() => decoder.Read(buffer, 0, 1024)); }
public void TestCombinedCrcStream_ExactLengthRead() { BZip2DecoderStream decoder = new BZip2DecoderStream(new MemoryStream(InvalidCombinedCrcData), Ownership.Dispose); byte[] buffer = new byte[21]; Assert.Throws <InvalidDataException>(() => decoder.Read(buffer, 0, 21)); }
public void TestValidStream() { BZip2DecoderStream decoder = new BZip2DecoderStream(new MemoryStream(ValidData), Ownership.Dispose); byte[] buffer = new byte[1024]; int numRead = decoder.Read(buffer, 0, 1024); Assert.Equal(21, numRead); string s = Encoding.ASCII.GetString(buffer, 0, numRead); Assert.Equal("This is a test string", s); }
private void LoadRun(CompressedRun run) { int toCopy = (int)(run.SectorCount * Sizes.Sector); switch (run.Type) { case RunType.ZlibCompressed: _stream.Position = run.CompOffset + 2; // 2 byte zlib header using (DeflateStream ds = new DeflateStream(_stream, CompressionMode.Decompress, true)) { Utilities.ReadFully(ds, _decompBuffer, 0, toCopy); } break; case RunType.AdcCompressed: _stream.Position = run.CompOffset; byte[] compressed = Utilities.ReadFully(_stream, (int)run.CompLength); if (ADCDecompress(compressed, 0, compressed.Length, _decompBuffer, 0) != toCopy) { throw new InvalidDataException("Run too short when decompressed"); } break; case RunType.BZlibCompressed: using ( BZip2DecoderStream ds = new BZip2DecoderStream(new SubStream(_stream, run.CompOffset, run.CompLength), Ownership.None)) { Utilities.ReadFully(ds, _decompBuffer, 0, toCopy); } break; case RunType.Zeros: case RunType.Raw: break; default: throw new NotImplementedException("Unrecognized run type " + run.Type); } _activeRun = run; }