Skip to content

Instantly share code, notes, and snippets.

@enue
Last active November 30, 2018 23:30
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save enue/d8a37101946b6c117b224c915161b12b to your computer and use it in GitHub Desktop.
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