Use native version for LZFSE.

This commit is contained in:
2021-11-04 18:11:14 +00:00
parent 72c870528f
commit 3125fccace
2 changed files with 63 additions and 0 deletions

View File

@@ -73,6 +73,7 @@
<Compile Include="ADC.cs" /> <Compile Include="ADC.cs" />
<Compile Include="AppleRle.cs" /> <Compile Include="AppleRle.cs" />
<Compile Include="BZip2.cs" /> <Compile Include="BZip2.cs" />
<Compile Include="LZFSE.cs" />
<Compile Include="Native.cs" /> <Compile Include="Native.cs" />
<Compile Include="TeleDiskLzh.cs" /> <Compile Include="TeleDiskLzh.cs" />
<Compile Include="cuetools.net/CUETools.Codecs/*.cs" /> <Compile Include="cuetools.net/CUETools.Codecs/*.cs" />

62
Aaru.Compression/LZFSE.cs Normal file
View File

@@ -0,0 +1,62 @@
// /***************************************************************************
// Aaru Data Preservation Suite
// ----------------------------------------------------------------------------
//
// Filename : LZFSE.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : Compression algorithms.
//
// --[ License ] --------------------------------------------------------------
//
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation; either version 2.1 of the
// License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, see <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
// Copyright © 2011-2021 Natalia Portillo
// ****************************************************************************/
using System.Runtime.InteropServices;
namespace Aaru.Compression;
public class LZFSE
{
[DllImport("libAaru.Compression.Native", SetLastError = true)]
static extern nuint AARU_lzfse_decode_buffer(byte[] dst_buffer, nuint dst_size, byte[] src_buffer, nuint src_size,
byte[] scratch_buffer);
[DllImport("libAaru.Compression.Native", SetLastError = true)]
static extern nuint AARU_lzfse_encode_buffer(byte[] dst_buffer, nuint dst_size, byte[] src_buffer, nuint src_size,
byte[] scratch_buffer);
/// <summary>Decodes a buffer compressed with LZFSE</summary>
/// <param name="source">Encoded buffer</param>
/// <param name="destination">Buffer where to write the decoded data</param>
/// <returns>The number of decoded bytes</returns>
public static int DecodeBuffer(byte[] source, byte[] destination) => Native.IsSupported
? (int)
AARU_lzfse_decode_buffer(destination,
(nuint)destination.Length, source,
(nuint)source.Length, null) : 0;
/// <summary>Compresses a buffer using BZIP2</summary>
/// <param name="source">Data to compress</param>
/// <param name="destination">Buffer to store the compressed data</param>
/// <returns></returns>
public static int EncodeBuffer(byte[] source, byte[] destination) => Native.IsSupported
? (int)
AARU_lzfse_encode_buffer(destination,
(nuint)destination.Length, source,
(nuint)source.Length, null) : 0;
}