Add bzip2.

This commit is contained in:
2021-10-18 00:10:15 +01:00
parent 136ef87201
commit b97ff2770c
3 changed files with 32 additions and 0 deletions

View File

@@ -62,6 +62,9 @@ namespace AaruBenchmark
[Benchmark]
public void DotNetZip() => Compression.DotNetZip.Bzip2();
[Benchmark]
public void AaruNative() => Compression.AaruNative.Bzip2();
}
[SimpleJob(RuntimeMoniker.Net60)]

View File

@@ -12,6 +12,10 @@ namespace AaruBenchmark.Compression
[DllImport("libAaru.Compression.Native", SetLastError = true)]
static extern int adc_decode_buffer(byte[] dst_buffer, int dst_size, byte[] src_buffer, int src_size);
[DllImport("libAaru.Compression.Native", SetLastError = true)]
static extern int BZ2_bzBuffToBuffDecompress(byte[] dest, ref uint destLen, byte[] source, uint sourceLen,
int small, int verbosity);
public static void AppleRle()
{
const int bufferSize = 32768;
@@ -59,5 +63,30 @@ namespace AaruBenchmark.Compression
if(crc != "5a5a7388")
throw new InvalidDataException("Incorrect decompressed checksum");
}
public static void Bzip2()
{
const int bufferSize = 1048576;
byte[] input = new byte[1053934];
var fs = new FileStream(Path.Combine(Program.Folder, "bzip2.bz2"), FileMode.Open, FileAccess.Read);
fs.Read(input, 0, input.Length);
fs.Close();
fs.Dispose();
byte[] output = new byte[bufferSize];
uint realSize = (uint)output.Length;
int bzError = BZ2_bzBuffToBuffDecompress(output, ref realSize, input, (uint)input.Length, 0, 0);
if(realSize != 1048576)
throw new InvalidDataException("Incorrect decompressed size");
string crc = Crc32Context.Data(output, realSize, out _);
if(crc != "c64059c0")
throw new InvalidDataException("Incorrect decompressed checksum");
}
}
}

Binary file not shown.