Add lzip.

This commit is contained in:
2021-10-18 02:45:32 +01:00
parent b97ff2770c
commit 1ad8b79b1e
7 changed files with 76 additions and 0 deletions

View File

@@ -42,6 +42,10 @@
<Content Include="libAaru.Compression.Native.so"> <Content Include="libAaru.Compression.Native.so">
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content> </Content>
<None Remove="data\lzip.lz"/>
<Content Include="data\lzip.lz">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@@ -67,6 +67,15 @@ namespace AaruBenchmark
public void AaruNative() => Compression.AaruNative.Bzip2(); public void AaruNative() => Compression.AaruNative.Bzip2();
} }
public class LzipBenchs
{
[Benchmark(Baseline = true)]
public void SharpCompress() => Compression.SharpCompress.Lzip();
[Benchmark]
public void AaruNative() => Compression.AaruNative.Lzip();
}
[SimpleJob(RuntimeMoniker.Net60)] [SimpleJob(RuntimeMoniker.Net60)]
public class Adler32Benchs public class Adler32Benchs
{ {

View File

@@ -16,6 +16,9 @@ namespace AaruBenchmark.Compression
static extern int BZ2_bzBuffToBuffDecompress(byte[] dest, ref uint destLen, byte[] source, uint sourceLen, static extern int BZ2_bzBuffToBuffDecompress(byte[] dest, ref uint destLen, byte[] source, uint sourceLen,
int small, int verbosity); int small, int verbosity);
[DllImport("libAaru.Compression.Native", SetLastError = true)]
static extern int lzip_decode_buffer(byte[] dst_buffer, int dst_size, byte[] src_buffer, int src_size);
public static void AppleRle() public static void AppleRle()
{ {
const int bufferSize = 32768; const int bufferSize = 32768;
@@ -88,5 +91,29 @@ namespace AaruBenchmark.Compression
if(crc != "c64059c0") if(crc != "c64059c0")
throw new InvalidDataException("Incorrect decompressed checksum"); throw new InvalidDataException("Incorrect decompressed checksum");
} }
public static void Lzip()
{
const int bufferSize = 1048576;
byte[] input = new byte[1062874];
var fs = new FileStream(Path.Combine(Program.Folder, "lzip.lz"), FileMode.Open, FileAccess.Read);
fs.Read(input, 0, input.Length);
fs.Close();
fs.Dispose();
byte[] output = new byte[bufferSize];
int realSize = lzip_decode_buffer(output, output.Length, input, input.Length);
if(realSize != 1048576)
throw new InvalidDataException("Incorrect decompressed size");
string crc = Crc32Context.Data(output, (uint)realSize, out _);
if(crc != "c64059c0")
throw new InvalidDataException("Incorrect decompressed checksum");
}
} }
} }

View File

@@ -4,6 +4,7 @@ using SharpCompress.Compressors;
using SharpCompress.Compressors.ADC; using SharpCompress.Compressors.ADC;
using SharpCompress.Compressors.BZip2; using SharpCompress.Compressors.BZip2;
using SharpCompress.Compressors.Deflate; using SharpCompress.Compressors.Deflate;
using SharpCompress.Compressors.LZMA;
namespace AaruBenchmark.Compression namespace AaruBenchmark.Compression
{ {
@@ -100,5 +101,39 @@ namespace AaruBenchmark.Compression
if(crc != "5a5a7388") if(crc != "5a5a7388")
throw new InvalidDataException("Incorrect decompressed checksum"); throw new InvalidDataException("Incorrect decompressed checksum");
} }
public static void Lzip()
{
var _dataStream = new FileStream(Path.Combine(Program.Folder, "lzip.lz"), FileMode.Open, FileAccess.Read);
Stream str = new LZipStream(_dataStream, CompressionMode.Decompress);
byte[] compressed = new byte[1048576];
int pos = 0;
int left = 1048576;
bool oneZero = false;
while(left > 0)
{
int done = str.Read(compressed, pos, left);
if(done == 0)
{
if(oneZero)
throw new IOException("Could not read the file!");
oneZero = true;
}
left -= done;
pos += done;
}
str.Close();
str.Dispose();
string crc = Crc32Context.Data(compressed, 1048576, out _);
if(crc != "c64059c0")
throw new InvalidDataException("Incorrect decompressed checksum");
}
} }
} }

View File

@@ -18,6 +18,7 @@ namespace AaruBenchmark
BenchmarkRunner.Run<TeleDiskLzhBenchs>(config); BenchmarkRunner.Run<TeleDiskLzhBenchs>(config);
BenchmarkRunner.Run<GzipBenchs>(config); BenchmarkRunner.Run<GzipBenchs>(config);
BenchmarkRunner.Run<Bzip2Benchs>(config); BenchmarkRunner.Run<Bzip2Benchs>(config);
BenchmarkRunner.Run<LzipBenchs>(config);
BenchmarkRunner.Run<Adler32Benchs>(config); BenchmarkRunner.Run<Adler32Benchs>(config);
BenchmarkRunner.Run<Crc16CcittBenchs>(config); BenchmarkRunner.Run<Crc16CcittBenchs>(config);
BenchmarkRunner.Run<Crc16Benchs>(config); BenchmarkRunner.Run<Crc16Benchs>(config);

BIN
AaruBenchmark/data/lzip.lz Normal file

Binary file not shown.

Binary file not shown.