Add support for in-memory ReadWriteZipFiles.

This commit is contained in:
Paul Chote
2025-03-02 21:24:46 +00:00
committed by Gustas Kažukauskas
parent fceb8a479d
commit 1707dbd92b

View File

@@ -98,11 +98,11 @@ namespace OpenRA.FileSystem
{
readonly MemoryStream pkgStream = new();
public ReadWriteZipFile(string filename, bool create = false)
public ReadWriteZipFile(string filename = null, bool create = false)
{
// SharpZipLib breaks when asked to update archives loaded from outside streams or files
// We can work around this by creating a clean in-memory-only file, cutting all outside references
if (!create)
if (!string.IsNullOrEmpty(filename) && !create)
{
using (var copy = new MemoryStream(File.ReadAllBytes(filename)))
{
@@ -122,7 +122,8 @@ namespace OpenRA.FileSystem
void Commit()
{
File.WriteAllBytes(Name, pkgStream.ToArray());
if (!string.IsNullOrEmpty(Name))
File.WriteAllBytes(Name, pkgStream.ToArray());
}
public void Update(string filename, byte[] contents)