mirror of
https://github.com/KillzXGaming/Switch-Toolbox
synced 2024-11-25 22:10:22 +00:00
0c126e4155
Rewrote the compression handling from scatch. It's way easier and cleaner to add new formats code wise as it's handled like file formats. Added wip TVOL support (Touhou Azure Reflections) Added XCI support. Note I plan to improve NSP, XCI, NCA, etc later for exefs exporting. The compression rework now compresses via streams, so files get decompressed properly within archives as streams. Added hyrule warriors bin.gz compression along with archive rebuilding. Note i do not have texture rebuilding done just yet.
58 lines
1.5 KiB
C#
58 lines
1.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.IO;
|
|
using System.IO.Compression;
|
|
using System.Threading.Tasks;
|
|
using Toolbox.Library.IO;
|
|
using K4os.Compression.LZ4.Streams;
|
|
|
|
namespace Toolbox.Library
|
|
{
|
|
public class lz4 : ICompressionFormat
|
|
{
|
|
public string[] Description { get; set; } = new string[] { "LZ4 Compression" };
|
|
public string[] Extension { get; set; } = new string[] { "*.lz4" };
|
|
|
|
public override string ToString() { return "lz4"; }
|
|
|
|
public bool Identify(Stream stream, string fileName)
|
|
{
|
|
return false;
|
|
|
|
using (var reader = new FileReader(stream, true))
|
|
{
|
|
uint DecompressedSize = reader.ReadUInt32();
|
|
uint magicCheck = reader.ReadUInt32();
|
|
|
|
bool LZ4FDefault = magicCheck == 0x184D2204;
|
|
|
|
return LZ4FDefault;
|
|
}
|
|
}
|
|
|
|
public bool CanCompress { get; } = true;
|
|
|
|
public Stream Decompress(Stream stream)
|
|
{
|
|
using (MemoryStream mem = new MemoryStream())
|
|
{
|
|
using (var source = LZ4Stream.Decode(stream))
|
|
{
|
|
source.CopyTo(mem);
|
|
}
|
|
return mem;
|
|
}
|
|
}
|
|
|
|
public Stream Compress(Stream stream)
|
|
{
|
|
var mem = new MemoryStream();
|
|
using (var source = LZ4Stream.Encode(stream, null, true))
|
|
{
|
|
source.CopyTo(mem);
|
|
}
|
|
return mem;
|
|
}
|
|
}
|
|
}
|