-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathZipDirectory.cs
More file actions
71 lines (57 loc) · 2.73 KB
/
ZipDirectory.cs
File metadata and controls
71 lines (57 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using System.Diagnostics;
using Ramstack.FileSystem.Utilities;
namespace Ramstack.FileSystem.Zip;
/// <summary>
/// Represents directory contents and file information within a ZIP archive for the specified path.
/// </summary>
[DebuggerTypeProxy(typeof(ZipDirectoryDebuggerProxy))]
internal sealed class ZipDirectory : VirtualDirectory
{
private readonly ZipFileSystem _fileSystem;
private readonly List<VirtualNode> _nodes = [];
/// <inheritdoc />
public override IVirtualFileSystem FileSystem => _fileSystem;
/// <summary>
/// Initializes a new instance of the <see cref="ZipDirectory"/> class.
/// </summary>
/// <param name="fileSystem">The file system associated with this directory.</param>
/// <param name="path">The path of the directory.</param>
public ZipDirectory(ZipFileSystem fileSystem, string path) : base(path) =>
_fileSystem = fileSystem;
/// <inheritdoc />
protected override ValueTask<VirtualNodeProperties?> GetPropertiesCoreAsync(CancellationToken cancellationToken) =>
new ValueTask<VirtualNodeProperties?>(VirtualNodeProperties.None);
/// <inheritdoc />
protected override ValueTask<bool> ExistsCoreAsync(CancellationToken cancellationToken) =>
new ValueTask<bool>(true);
/// <inheritdoc />
protected override ValueTask CreateCoreAsync(CancellationToken cancellationToken) =>
default;
/// <inheritdoc />
protected override ValueTask DeleteCoreAsync(CancellationToken cancellationToken) =>
default;
/// <inheritdoc />
protected override IAsyncEnumerable<VirtualNode> GetFileNodesCoreAsync(CancellationToken cancellationToken) =>
_nodes.ToAsyncEnumerable();
/// <summary>
/// Register a file node associated with this directory.
/// </summary>
/// <param name="node">The file node associated with this directory.</param>
internal void RegisterNode(VirtualNode node) =>
_nodes.Add(node);
#region Inner type: ZipDirectoryDebuggerProxy
/// <summary>
/// Represents a debugger proxy for viewing the contents of a <see cref="ZipDirectory"/> instance.
/// </summary>
/// <param name="directory">The <see cref="ZipDirectory"/> instance to provide debugging information for.</param>
private sealed class ZipDirectoryDebuggerProxy(ZipDirectory directory)
{
/// <summary>
/// Gets an array of <see cref="VirtualNode"/> instances representing
/// the files within the associated <see cref="ZipDirectory"/>.
/// </summary>
[DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
public VirtualNode[] Nodes { get; } = directory._nodes.ToArray();
}
#endregion
}