WIP -- before another refactor

This commit is contained in:
2025-12-23 20:32:27 -07:00
parent 06a0ec28eb
commit 5230c620e8
2 changed files with 7 additions and 53 deletions

View File

@@ -1,15 +1,12 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Text;
namespace Slang;
public static class GlobalCode
{
public const string SLANG_REF = "#SLANG_REF:";
public const string SLANG_SRC = "#SLANG_SRC:";
public const string SLANG_SRC = "SLANG_SRC";
// This is a Dictionary of ENCODED source code, compressed
// so that save file data is smaller
@@ -110,43 +107,11 @@ public static class GlobalCode
private static string EncodeSource(string source)
{
if (string.IsNullOrEmpty(source))
{
return "";
}
byte[] bytes = Encoding.UTF8.GetBytes(source);
using (var memoryStream = new MemoryStream())
{
using (var gzipStream = new GZipStream(memoryStream, CompressionMode.Compress))
{
gzipStream.Write(bytes, 0, bytes.Length);
}
return Convert.ToBase64String(memoryStream.ToArray());
}
return SlangFormatter.EncodeSource(source, SLANG_SRC);
}
private static string DecodeSource(string source)
{
if (string.IsNullOrEmpty(source))
{
return "";
}
byte[] compressedBytes = Convert.FromBase64String(source);
using (var memoryStream = new MemoryStream(compressedBytes))
{
using (var gzipStream = new GZipStream(memoryStream, CompressionMode.Decompress))
{
using (var outputStream = new MemoryStream())
{
gzipStream.CopyTo(outputStream);
return Encoding.UTF8.GetString(outputStream.ToArray());
}
}
}
return SlangFormatter.DecodeSource(source, SLANG_SRC);
}
}