AxibugEmuOnline/AxibugEmuOnline.Client/Assets/MyNes.Core/ZlipWrapper.cs

40 lines
1.2 KiB
C#
Raw Normal View History

2024-07-03 18:15:28 +08:00
using System.IO;
using ComponentAce.Compression.Libs.zlib;
2024-07-03 18:22:22 +08:00
namespace MyNes.Core
2024-07-03 18:15:28 +08:00
{
2024-07-03 18:22:22 +08:00
internal class ZlipWrapper
{
internal static void CompressData(byte[] inData, out byte[] outData)
{
using MemoryStream memoryStream = new MemoryStream();
using ZOutputStream zOutputStream = new ZOutputStream(memoryStream, -1);
using Stream input = new MemoryStream(inData);
CopyStream(input, zOutputStream);
zOutputStream.finish();
outData = memoryStream.ToArray();
}
2024-07-03 18:15:28 +08:00
2024-07-03 18:22:22 +08:00
internal static void DecompressData(byte[] inData, out byte[] outData)
{
using MemoryStream memoryStream = new MemoryStream();
using ZOutputStream zOutputStream = new ZOutputStream(memoryStream);
using Stream input = new MemoryStream(inData);
CopyStream(input, zOutputStream);
zOutputStream.finish();
outData = memoryStream.ToArray();
}
2024-07-03 18:15:28 +08:00
2024-07-03 18:22:22 +08:00
internal static void CopyStream(Stream input, Stream output)
{
byte[] buffer = new byte[2000];
int count;
while ((count = input.Read(buffer, 0, 2000)) > 0)
{
output.Write(buffer, 0, count);
}
output.Flush();
}
}
2024-07-03 15:40:13 +08:00
}