Support serializing/loading ReadWriteZipFile as base64 string.

This commit is contained in:
Paul Chote
2025-04-17 17:45:48 +01:00
committed by Gustas Kažukauskas
parent 5292919917
commit 6be947bbf0

View File

@@ -120,6 +120,23 @@ namespace OpenRA.FileSystem
entry.ExtraData = null;
}
public ReadWriteZipFile(byte[] data)
{
using (var copy = new MemoryStream(data))
{
pkgStream.Capacity = (int)copy.Length;
copy.CopyTo(pkgStream);
}
pkgStream.Position = 0;
pkg = new ZipFile(pkgStream);
Name = null;
// Remove subfields that can break ZIP updating.
foreach (ZipEntry entry in pkg)
entry.ExtraData = null;
}
void Commit()
{
if (!string.IsNullOrEmpty(Name))
@@ -141,6 +158,16 @@ namespace OpenRA.FileSystem
pkg.CommitUpdate();
Commit();
}
public static ReadWriteZipFile FromBase64String(string data)
{
return new ReadWriteZipFile(Convert.FromBase64String(data));
}
public string ToBase64String()
{
return Convert.ToBase64String(pkgStream.ToArray());
}
}
sealed class ZipFolder : IReadOnlyPackage