1
0
mirror of synced 2024-12-01 02:27:22 +01:00
Switch-Toolbox/Switch_Toolbox_Library/Compression/Formats/ZCMP.cs
KillzXGaming 0c126e4155 More improvements.
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.
2019-09-15 19:13:01 -04:00

50 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;
namespace Toolbox.Library
{
public class ZCMP : ICompressionFormat
{
public string[] Description { get; set; } = new string[] { "ZLIB Compression (ZCMP)" };
public string[] Extension { get; set; } = new string[] { "*.cmp" };
public bool Identify(Stream stream, string fileName)
{
using (var reader = new FileReader(stream, true))
{
return reader.CheckSignature(4, "ZCMP");
}
}
public bool CanCompress { get; } = true;
public Stream Decompress(Stream stream)
{
using (var br = new FileReader(stream, true))
{
var ms = new System.IO.MemoryStream();
br.BaseStream.Position = 130;
using (var ds = new DeflateStream(new MemoryStream(br.ReadBytes((int)br.BaseStream.Length - 80)), CompressionMode.Decompress))
ds.CopyTo(ms);
return ms;
}
}
public Stream Compress(Stream stream)
{
var mem = new MemoryStream();
mem.Write(new byte[] { 0x78, 0xDA }, 0, 2);
using (var zipStream = new DeflateStream(mem, CompressionMode.Compress))
{
zipStream.CopyTo(stream);
return mem;
}
}
}
}