Skip to content

Instantly share code, notes, and snippets.

@enue enue/Compression.cs
Last active Nov 30, 2018

Embed
What would you like to do?
Deflate圧縮
using UnityEngine;
using System.Collections;
using System;
using System.Text;
using System.IO;
using System.IO.Compression;
// Unity2018.3.0b12
namespace TSKT
{
public static class DeflateUtil
{
static public byte[] Compress(byte[] bytes)
{
using (var compressed = new MemoryStream())
{
using (var deflateStream = new DeflateStream(compressed, CompressionMode.Compress))
{
deflateStream.Write(bytes, 0, bytes.Length);
}
return compressed.ToArray();
}
}
static public byte[] Decompress(byte[] bytes)
{
using (var compressed = new MemoryStream(bytes))
{
using (var deflateStream = new DeflateStream(compressed, CompressionMode.Decompress))
{
using (var decompressed = new MemoryStream())
{
deflateStream.CopyTo(decompressed);
return decompressed.ToArray();
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.