2019-07-01 19:44:19 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.IO.Compression;
|
|
|
|
|
using System.Threading.Tasks;
|
2019-07-16 21:35:21 +00:00
|
|
|
|
using Toolbox.Library.IO;
|
2019-07-01 19:44:19 +00:00
|
|
|
|
|
2019-07-16 21:35:21 +00:00
|
|
|
|
namespace Toolbox.Library
|
2019-07-01 19:44:19 +00:00
|
|
|
|
{
|
|
|
|
|
public class ZCMP : ICompressionFormat
|
|
|
|
|
{
|
|
|
|
|
public string[] Description { get; set; } = new string[] { "ZLIB Compression (ZCMP)" };
|
|
|
|
|
public string[] Extension { get; set; } = new string[] { "*.cmp" };
|
|
|
|
|
|
2019-09-15 23:13:01 +00:00
|
|
|
|
public bool Identify(Stream stream, string fileName)
|
2019-07-01 19:44:19 +00:00
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|