[성현모] DataModel분리, TestResult 페이지/기능 추가
This commit is contained in:
53
Projects/SystemX.Core/SystemX.Core/Utils/Gzip.cs
Normal file
53
Projects/SystemX.Core/SystemX.Core/Utils/Gzip.cs
Normal file
@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SystemX.Core.Utils
|
||||
{
|
||||
public static class Gzip
|
||||
{
|
||||
public static string Compress(string stringData)
|
||||
{
|
||||
byte[] bytes = Encoding.UTF8.GetBytes(stringData);
|
||||
byte[] inArray = null;
|
||||
using (MemoryStream memoryStream = new MemoryStream())
|
||||
{
|
||||
using (GZipStream gZipStream = new GZipStream(memoryStream, CompressionMode.Compress))
|
||||
{
|
||||
gZipStream.Write(bytes, 0, bytes.Length);
|
||||
}
|
||||
|
||||
inArray = memoryStream.ToArray();
|
||||
}
|
||||
|
||||
return Convert.ToBase64String(inArray);
|
||||
}
|
||||
|
||||
public static string Decompression(string compressedDataStr)
|
||||
{
|
||||
string result = null;
|
||||
byte[] buffer = Convert.FromBase64String(compressedDataStr);
|
||||
using (MemoryStream stream = new MemoryStream(buffer))
|
||||
{
|
||||
using GZipStream stream2 = new GZipStream(stream, CompressionMode.Decompress);
|
||||
using StreamReader streamReader = new StreamReader(stream2);
|
||||
result = streamReader.ReadToEnd();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static string GzipCompress(this string stringData)
|
||||
{
|
||||
return Compress(stringData);
|
||||
}
|
||||
|
||||
public static string GzipDecompress(this string compressedDataStr)
|
||||
{
|
||||
return Decompression(compressedDataStr);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user