mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-05-07 12:16:04 +00:00
Revert Cache Compression
This commit is contained in:
parent
1742ca385b
commit
f84f2195c3
|
@ -214,15 +214,7 @@ namespace WelsonJS.Launcher
|
||||||
{
|
{
|
||||||
if (File.Exists(cachePath))
|
if (File.Exists(cachePath))
|
||||||
{
|
{
|
||||||
byte[] raw = File.ReadAllBytes(cachePath);
|
data = File.ReadAllBytes(cachePath);
|
||||||
|
|
||||||
if (isMetadata)
|
|
||||||
{
|
|
||||||
data = raw;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
data = IsCompressed(raw) ? Decompress(raw) : raw;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -264,8 +256,7 @@ namespace WelsonJS.Launcher
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save the cache
|
// Save the cache
|
||||||
byte[] compressed = Compress(data);
|
File.WriteAllBytes(cachePath, data);
|
||||||
File.WriteAllBytes(cachePath, compressed);
|
|
||||||
|
|
||||||
// Save the cache meta
|
// Save the cache meta
|
||||||
File.WriteAllBytes($"{cachePath}.meta", Encoding.UTF8.GetBytes(mimeType));
|
File.WriteAllBytes($"{cachePath}.meta", Encoding.UTF8.GetBytes(mimeType));
|
||||||
|
@ -370,34 +361,5 @@ namespace WelsonJS.Launcher
|
||||||
return memoryStream.ToArray();
|
return memoryStream.ToArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private byte[] Compress(byte[] data)
|
|
||||||
{
|
|
||||||
using (var output = new MemoryStream())
|
|
||||||
{
|
|
||||||
using (var gzip = new GZipStream(output, CompressionMode.Compress))
|
|
||||||
{
|
|
||||||
gzip.Write(data, 0, data.Length);
|
|
||||||
}
|
|
||||||
return output.ToArray(); // includes GZip signature
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private byte[] Decompress(byte[] data)
|
|
||||||
{
|
|
||||||
using (var input = new MemoryStream(data))
|
|
||||||
using (var gzip = new GZipStream(input, CompressionMode.Decompress))
|
|
||||||
using (var output = new MemoryStream())
|
|
||||||
{
|
|
||||||
gzip.CopyTo(output);
|
|
||||||
return output.ToArray();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool IsCompressed(byte[] data)
|
|
||||||
{
|
|
||||||
// GZip signature: 0x1F 0x8B
|
|
||||||
return data != null && data.Length >= 2 && data[0] == 0x1F && data[1] == 0x8B;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user