1
1
// Licensed to the .NET Foundation under one or more agreements.
2
2
// The .NET Foundation licenses this file to you under the MIT license.
3
3
4
+ using System . Linq ;
5
+ using System . Runtime . InteropServices ;
4
6
using System . Text ;
7
+ using System . Threading . Tasks ;
5
8
using Xunit ;
6
9
7
10
namespace System . IO . Compression . Tests
@@ -136,6 +139,42 @@ public void UnixExtractFilePermissionsCompat(string zipName, string expectedPerm
136
139
}
137
140
}
138
141
142
+ [ Fact ]
143
+ [ PlatformSpecific ( TestPlatforms . AnyUnix & ~ TestPlatforms . Browser ) ]
144
+ public async Task CanZipNamedPipe ( )
145
+ {
146
+ string destPath = Path . Combine ( TestDirectory , "dest.zip" ) ;
147
+
148
+ string subFolderPath = Path . Combine ( TestDirectory , "subfolder" ) ;
149
+ string fifoPath = Path . Combine ( subFolderPath , "namedPipe" ) ;
150
+ Directory . CreateDirectory ( subFolderPath ) ; // mandatory before calling mkfifo
151
+ Assert . Equal ( 0 , mkfifo ( fifoPath , 438 /* 666 in octal */ ) ) ;
152
+
153
+ byte [ ] contentBytes = { 1 , 2 , 3 , 4 , 5 } ;
154
+
155
+ await Task . WhenAll (
156
+ Task . Run ( ( ) =>
157
+ {
158
+ using FileStream fs = new ( fifoPath , FileMode . Open , FileAccess . Write , FileShare . Read ) ;
159
+ foreach ( byte content in contentBytes )
160
+ {
161
+ fs . WriteByte ( content ) ;
162
+ }
163
+ } ) ,
164
+ Task . Run ( ( ) =>
165
+ {
166
+ ZipFile . CreateFromDirectory ( subFolderPath , destPath ) ;
167
+
168
+ using ZipArchive zippedFolder = ZipFile . OpenRead ( destPath ) ;
169
+ using Stream unzippedPipe = zippedFolder . Entries . Single ( ) . Open ( ) ;
170
+
171
+ byte [ ] readBytes = new byte [ contentBytes . Length ] ;
172
+ Assert . Equal ( contentBytes . Length , unzippedPipe . Read ( readBytes ) ) ;
173
+ Assert . Equal < byte > ( contentBytes , readBytes ) ;
174
+ Assert . Equal ( 0 , unzippedPipe . Read ( readBytes ) ) ; // EOF
175
+ } ) ) ;
176
+ }
177
+
139
178
private static string GetExpectedPermissions ( string expectedPermissions )
140
179
{
141
180
if ( string . IsNullOrEmpty ( expectedPermissions ) )
@@ -156,5 +195,8 @@ private static string GetExpectedPermissions(string expectedPermissions)
156
195
157
196
return expectedPermissions ;
158
197
}
198
+
199
+ [ DllImport ( "libc" , SetLastError = true ) ]
200
+ private static extern int mkfifo ( string path , int mode ) ;
159
201
}
160
202
}
0 commit comments