mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
[+] 接入ET8服务端
[+] 接入ET8服务端
This commit is contained in:
97
Assets/GameScripts/DotNet/Core/Helper/ZipHelper.cs
Normal file
97
Assets/GameScripts/DotNet/Core/Helper/ZipHelper.cs
Normal file
@@ -0,0 +1,97 @@
|
||||
using System.IO;
|
||||
using ICSharpCode.SharpZipLib.Zip.Compression;
|
||||
|
||||
namespace ET
|
||||
{
|
||||
public static class ZipHelper
|
||||
{
|
||||
public static byte[] Compress(byte[] content)
|
||||
{
|
||||
//return content;
|
||||
Deflater compressor = new Deflater();
|
||||
compressor.SetLevel(Deflater.BEST_COMPRESSION);
|
||||
|
||||
compressor.SetInput(content);
|
||||
compressor.Finish();
|
||||
|
||||
using (MemoryStream bos = new MemoryStream(content.Length))
|
||||
{
|
||||
var buf = new byte[1024];
|
||||
while (!compressor.IsFinished)
|
||||
{
|
||||
int n = compressor.Deflate(buf);
|
||||
bos.Write(buf, 0, n);
|
||||
}
|
||||
return bos.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] Decompress(byte[] content)
|
||||
{
|
||||
return Decompress(content, 0, content.Length);
|
||||
}
|
||||
|
||||
public static byte[] Decompress(byte[] content, int offset, int count)
|
||||
{
|
||||
//return content;
|
||||
Inflater decompressor = new Inflater();
|
||||
decompressor.SetInput(content, offset, count);
|
||||
|
||||
using (MemoryStream bos = new MemoryStream(content.Length))
|
||||
{
|
||||
var buf = new byte[1024];
|
||||
while (!decompressor.IsFinished)
|
||||
{
|
||||
int n = decompressor.Inflate(buf);
|
||||
bos.Write(buf, 0, n);
|
||||
}
|
||||
return bos.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
|
||||
namespace ET
|
||||
{
|
||||
public static class ZipHelper
|
||||
{
|
||||
public static byte[] Compress(byte[] content)
|
||||
{
|
||||
using (MemoryStream ms = new MemoryStream())
|
||||
using (DeflateStream stream = new DeflateStream(ms, CompressionMode.Compress, true))
|
||||
{
|
||||
stream.Write(content, 0, content.Length);
|
||||
return ms.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] Decompress(byte[] content)
|
||||
{
|
||||
return Decompress(content, 0, content.Length);
|
||||
}
|
||||
|
||||
public static byte[] Decompress(byte[] content, int offset, int count)
|
||||
{
|
||||
using (MemoryStream ms = new MemoryStream())
|
||||
using (DeflateStream stream = new DeflateStream(new MemoryStream(content, offset, count), CompressionMode.Decompress, true))
|
||||
{
|
||||
byte[] buffer = new byte[1024];
|
||||
while (true)
|
||||
{
|
||||
int bytesRead = stream.Read(buffer, 0, 1024);
|
||||
if (bytesRead == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
ms.Write(buffer, 0, bytesRead);
|
||||
}
|
||||
return ms.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
Reference in New Issue
Block a user