aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS.WinForms/Applications/Downloader.cs
diff options
context:
space:
mode:
authorMichael <[email protected]>2017-02-09 20:32:53 -0500
committerMichael <[email protected]>2017-02-09 20:32:53 -0500
commitde14574800ed21765e1ac6bba1d19b774f477c29 (patch)
treeb9d5ce4ce01e4e930e546ff23fc70a7ad32356bf /ShiftOS.WinForms/Applications/Downloader.cs
parentd6b2b155264e7a4b576c956530915f66d97b3eac (diff)
downloadshiftos_thereturn-de14574800ed21765e1ac6bba1d19b774f477c29.tar.gz
shiftos_thereturn-de14574800ed21765e1ac6bba1d19b774f477c29.tar.bz2
shiftos_thereturn-de14574800ed21765e1ac6bba1d19b774f477c29.zip
Compress shop items on server-side.
Diffstat (limited to 'ShiftOS.WinForms/Applications/Downloader.cs')
-rw-r--r--ShiftOS.WinForms/Applications/Downloader.cs30
1 files changed, 30 insertions, 0 deletions
diff --git a/ShiftOS.WinForms/Applications/Downloader.cs b/ShiftOS.WinForms/Applications/Downloader.cs
index dfa2425..2f33462 100644
--- a/ShiftOS.WinForms/Applications/Downloader.cs
+++ b/ShiftOS.WinForms/Applications/Downloader.cs
@@ -12,6 +12,8 @@ using ShiftOS.Engine;
using Newtonsoft.Json;
using ShiftOS.WinForms.Controls;
using ShiftOS.WinForms.Tools;
+using System.IO;
+using System.IO.Compression;
namespace ShiftOS.WinForms.Applications
{
@@ -113,6 +115,34 @@ namespace ShiftOS.WinForms.Applications
public static event Action<Download> DownloadStarted;
+ public static string Compress(string s)
+ {
+ var bytes = Encoding.Unicode.GetBytes(s);
+ using (var msi = new MemoryStream(bytes))
+ using (var mso = new MemoryStream())
+ {
+ using (var gs = new GZipStream(mso, CompressionMode.Compress))
+ {
+ msi.CopyTo(gs);
+ }
+ return Convert.ToBase64String(mso.ToArray());
+ }
+ }
+
+ public static string Decompress(string s)
+ {
+ var bytes = Convert.FromBase64String(s);
+ using (var msi = new MemoryStream(bytes))
+ using (var mso = new MemoryStream())
+ {
+ using (var gs = new GZipStream(msi, CompressionMode.Decompress))
+ {
+ gs.CopyTo(mso);
+ }
+ return Encoding.Unicode.GetString(mso.ToArray());
+ }
+ }
+
public static void StartDownload(Download down)
{
var t = new Thread(() =>