Files
Aaru/Aaru.Images/Apridisk/Compression.cs

65 lines
2.1 KiB
C#
Raw Normal View History

// /***************************************************************************
2020-02-27 12:31:25 +00:00
// Aaru Data Preservation Suite
// ----------------------------------------------------------------------------
//
// Filename : Compression.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : Disk image plugins.
//
// --[ Description ] ----------------------------------------------------------
//
// Contains compression algorithm for Apridisk disk images.
//
// --[ 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/>.
//
// ----------------------------------------------------------------------------
2022-12-03 16:07:10 +00:00
// Copyright © 2011-2023 Natalia Portillo
// ****************************************************************************/
using System;
using System.IO;
namespace Aaru.Images;
2022-03-06 13:29:38 +00:00
public sealed partial class Apridisk
{
2022-03-06 13:29:38 +00:00
static uint Decompress(byte[] compressed, out byte[] decompressed)
{
2023-10-03 23:34:59 +01:00
var readp = 0;
2022-03-06 13:29:38 +00:00
int cLen = compressed.Length;
var buffer = new MemoryStream();
2022-03-06 13:29:38 +00:00
uint uLen = 0;
2022-03-06 13:29:38 +00:00
while(cLen >= 3)
{
2023-10-03 23:34:59 +01:00
var blklen = BitConverter.ToUInt16(compressed, readp);
2022-03-06 13:29:38 +00:00
readp += 2;
2023-10-03 23:34:59 +01:00
for(var i = 0; i < blklen; i++)
2022-03-06 13:29:38 +00:00
buffer.WriteByte(compressed[readp]);
2022-03-06 13:29:38 +00:00
uLen += blklen;
readp++;
cLen -= 3;
}
2022-03-06 13:29:38 +00:00
decompressed = buffer.ToArray();
2020-02-29 18:03:35 +00:00
2022-03-06 13:29:38 +00:00
return uLen;
}
}