diff --git a/Aaru.Compression/Aaru.Compression.csproj b/Aaru.Compression/Aaru.Compression.csproj index b1026aa80..63f3f4065 100644 --- a/Aaru.Compression/Aaru.Compression.csproj +++ b/Aaru.Compression/Aaru.Compression.csproj @@ -84,6 +84,7 @@ + diff --git a/Aaru.Compression/StuffIt/ShrinkWrap.cs b/Aaru.Compression/StuffIt/ShrinkWrap.cs new file mode 100644 index 000000000..679fb2e46 --- /dev/null +++ b/Aaru.Compression/StuffIt/ShrinkWrap.cs @@ -0,0 +1,58 @@ +// /*************************************************************************** +// Aaru Data Preservation Suite +// ---------------------------------------------------------------------------- +// +// Filename : ShrinkWrap.cs +// Author(s) : Natalia Portillo +// +// 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 . +// +// ---------------------------------------------------------------------------- +// Copyright © 2011-2026 Natalia Portillo +// ****************************************************************************/ + +using System.Runtime.InteropServices; + +namespace Aaru.Compression.StuffIt; + +// ReSharper disable once InconsistentNaming +/// Implements Aladdin's ShrinkWrap StuffIt compression algorithm +public partial class ShrinkWrap +{ + /// Set to true if this algorithm is supported, false otherwise. + public static bool IsSupported => Native.IsSupported; + + [LibraryImport("libAaru.Compression.Native", SetLastError = true)] + private static partial int AARU_stuffit_shrinkwrap_decode_buffer(byte[] dst_buffer, ref nint dst_size, + byte[] src_buffer, nint src_size); + + /// Decodes a buffer compressed with ShrinkWrapper's StuffIt + /// Encoded buffer + /// Buffer where to write the decoded data + /// The number of decoded bytes + public static int DecodeBuffer(byte[] source, byte[] destination) + { + if(!Native.IsSupported) return 0; + + nint destLen = destination.Length; + + AARU_stuffit_shrinkwrap_decode_buffer(destination, ref destLen, source, source.Length); + + return (int)destLen; + } +} \ No newline at end of file