Closed FcAYH closed 5 months ago
ZipArchiveFileSystem
was added by a contributor, I have never used it, but looking at the code, try to dispose the ZipArchiveFileSystem
before exiting.
Yes, you are right, after I called zipFs.Dispose(), the changes were saved to the disk. But another question, if I want to modify it repeatedly and then save it repeatedly, I need to call Dispose() and then reread the local file. like this:
using Zio;
using Zio.FileSystems;
namespace ZioTest;
internal class ZipCreator
{
private ZipArchiveFileSystem _zipFs;
public void CreateZip(int index)
{
var path = Environment.CurrentDirectory;
//Console.WriteLine(path);
_zipFs = new ZipArchiveFileSystem($"{path}/test1.zip");
_zipFs.CreateDirectory($"/test{index}");
_zipFs.WriteAllText($"/test{index}/test.txt", "Hello World");
}
public void Close()
{
_zipFs.Dispose();
}
}
public class Program
{
public static void Main(string[] args)
{
ZipCreator creator = new();
creator.CreateZip(1);
creator.Close();
creator.CreateZip(2);
creator.Close();
}
}
These operations seems not very good for larger files. Is there any way to save changes manually like the belowing code:
using Zio;
using Zio.FileSystems;
namespace ZioTest;
internal class ZipCreator
{
private ZipArchiveFileSystem _zipFs;
public void CreateZip()
{
var path = Environment.CurrentDirectory;
//Console.WriteLine(path);
_zipFs = new ZipArchiveFileSystem($"{path}/test1.zip");
}
public void MakeContents(int index)
{
_zipFs.CreateDirectory($"/test{index}");
_zipFs.WriteAllText($"/test{index}/test.txt", "Hello World");
}
public void PersistenceToDisk()
{
_zipFs.FlushToDisk(); // Is there any method to save the zip file without closing the file system?
}
public void Close()
{
_zipFs.Dispose();
}
}
public class Program
{
public static void Main(string[] args)
{
ZipCreator creator = new();
creator.CreateZip();
creator.MakeContents(1);
creator.PersistenceToDisk();
creator.MakeContents(2);
creator.Close();
}
}
I see the ZipArchiveFileSystem.Dispose() called ZipArchive.Dispose(). So it should be ZipArchive.Dispose() that save its changes to disk. But I found that ZipArchive dosen't have a method to save itself unless call dispose. So I'm confused about the performance of calling dispose and then reloading the file every time I save the file to disk.
I think this is blocked by https://github.com/dotnet/runtime/issues/24149
I have used the ZipArchiveFileSystem to create a zip file on disk. And then I add some directory and files. But how can I save these modifications to disk?
I use the code below:
After I run the code, I got the zip file "test1.zip", but it's size is zero.
I have read the document and not found any information about save a FileSystem to disk.
dotnet version: 7.0 zio version: 0.17.0