33using Ramstack . FileSystem . Specification . Tests ;
44using Ramstack . FileSystem . Specification . Tests . Utilities ;
55
6+ #pragma warning disable CS0618 // Type or member is obsolete
7+
68namespace Ramstack . FileSystem . Zip ;
79
810[ TestFixture ]
@@ -24,6 +26,160 @@ public void Cleanup()
2426 File . Delete ( _path ) ;
2527 }
2628
29+ [ Test ]
30+ public async Task ZipArchive_WithIdenticalNameEntries ( )
31+ {
32+ using var fs = new ZipFileSystem ( CreateArchive ( ) ) ;
33+
34+ var list = await fs
35+ . GetFilesAsync ( "/1" )
36+ . ToArrayAsync ( ) ;
37+
38+ Assert . That (
39+ list . Length ,
40+ Is . EqualTo ( 1 ) ) ;
41+
42+ Assert . That (
43+ await list [ 0 ] . ReadAllBytesAsync ( ) ,
44+ Is . EquivalentTo ( "Hello, World!"u8 . ToArray ( ) ) ) ;
45+
46+ static MemoryStream CreateArchive ( )
47+ {
48+ var stream = new MemoryStream ( ) ;
49+ using ( var archive = new ZipArchive ( stream , ZipArchiveMode . Create , leaveOpen : true ) )
50+ {
51+ var a = archive . CreateEntry ( "1/text.txt" ) ;
52+ using ( var writer = a . Open ( ) )
53+ writer . Write ( "Hello, World!"u8 ) ;
54+
55+ archive . CreateEntry ( "1/text.txt" ) ;
56+ archive . CreateEntry ( @"1\text.txt" ) ;
57+ }
58+
59+ stream . Position = 0 ;
60+ return stream ;
61+ }
62+ }
63+
64+ [ Test ]
65+ public async Task ZipArchive_PrefixedEntries ( )
66+ {
67+ var archive = new ZipArchive ( CreateArchive ( ) , ZipArchiveMode . Read , leaveOpen : true ) ;
68+ using var fs = new ZipFileSystem ( archive ) ;
69+
70+ var directories = await fs
71+ . GetDirectoriesAsync ( "/" , "**" )
72+ . Select ( f =>
73+ f . FullName )
74+ . OrderBy ( f => f )
75+ . ToArrayAsync ( ) ;
76+
77+ var files = await fs
78+ . GetFilesAsync ( "/" , "**" )
79+ . Select ( f =>
80+ f . FullName )
81+ . OrderBy ( f => f )
82+ . ToArrayAsync ( ) ;
83+
84+ Assert . That ( files , Is . EquivalentTo (
85+ [
86+ "/1/text.txt" ,
87+ "/2/text.txt" ,
88+ "/3/text.txt" ,
89+ "/4/text.txt" ,
90+ "/5/text.txt" ,
91+ "/localhost/backup/text.txt" ,
92+ "/localhost/share/text.txt" ,
93+ "/server/backup/text.txt" ,
94+ "/server/share/text.txt" ,
95+ "/text.txt" ,
96+ "/text.xml"
97+ ] ) ) ;
98+
99+ Assert . That ( directories , Is . EquivalentTo (
100+ [
101+ "/1" ,
102+ "/2" ,
103+ "/3" ,
104+ "/4" ,
105+ "/5" ,
106+ "/localhost" ,
107+ "/localhost/backup" ,
108+ "/localhost/share" ,
109+ "/server" ,
110+ "/server/backup" ,
111+ "/server/share"
112+ ] ) ) ;
113+
114+ static MemoryStream CreateArchive ( )
115+ {
116+ var stream = new MemoryStream ( ) ;
117+ using ( var archive = new ZipArchive ( stream , ZipArchiveMode . Create , leaveOpen : true ) )
118+ {
119+ archive . CreateEntry ( @"D:\1/text.txt" ) ;
120+ archive . CreateEntry ( @"D:2\text.txt" ) ;
121+
122+ archive . CreateEntry ( @"\\?\D:\text.txt" ) ;
123+ archive . CreateEntry ( @"\\?\D:text.xml" ) ;
124+ archive . CreateEntry ( @"\\.\D:\3\text.txt" ) ;
125+ archive . CreateEntry ( @"//?/D:/4\text.txt" ) ;
126+ archive . CreateEntry ( @"//./D:\5/text.txt" ) ;
127+
128+ archive . CreateEntry ( @"\\?\UNC\localhost\share\text.txt" ) ;
129+ archive . CreateEntry ( @"\\.\unc\server\share\text.txt" ) ;
130+ archive . CreateEntry ( @"//?/UNC/localhost/backup\text.txt" ) ;
131+ archive . CreateEntry ( @"//./unc/server/backup\text.txt" ) ;
132+ }
133+
134+ stream . Position = 0 ;
135+ return stream ;
136+ }
137+ }
138+
139+ [ Test ]
140+ public async Task ZipArchive_Directories ( )
141+ {
142+ using var fs = new ZipFileSystem ( CreateArchive ( ) ) ;
143+
144+ var directories = await fs
145+ . GetDirectoriesAsync ( "/" , "**" )
146+ . Select ( f =>
147+ f . FullName )
148+ . OrderBy ( f => f )
149+ . ToArrayAsync ( ) ;
150+
151+ Assert . That ( directories , Is . EquivalentTo (
152+ [
153+ "/1" ,
154+ "/2" ,
155+ "/2/3" ,
156+ "/4" ,
157+ "/4/5" ,
158+ "/4/5/6"
159+ ] ) ) ;
160+
161+ static MemoryStream CreateArchive ( )
162+ {
163+ var stream = new MemoryStream ( ) ;
164+ using ( var archive = new ZipArchive ( stream , ZipArchiveMode . Create , leaveOpen : true ) )
165+ {
166+ archive . CreateEntry ( @"\1/" ) ;
167+ archive . CreateEntry ( @"\2/" ) ;
168+ archive . CreateEntry ( @"/2\" ) ;
169+ archive . CreateEntry ( @"/2\" ) ;
170+ archive . CreateEntry ( @"/2\" ) ;
171+ archive . CreateEntry ( @"/2\3/" ) ;
172+ archive . CreateEntry ( @"/2\3/" ) ;
173+ archive . CreateEntry ( @"/2\3/" ) ;
174+ archive . CreateEntry ( @"4\5/6\" ) ;
175+ }
176+
177+ stream . Position = 0 ;
178+ return stream ;
179+ }
180+ }
181+
182+
27183 /// <inheritdoc />
28184 protected override IVirtualFileSystem GetFileSystem ( ) =>
29185 new ZipFileSystem ( _path ) ;
0 commit comments