Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions src/libraries/System.IO.Compression.ZipFile/tests/ZipFile.Unix.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using Xunit;

namespace System.IO.Compression.Tests
Expand Down Expand Up @@ -136,6 +139,42 @@ public void UnixExtractFilePermissionsCompat(string zipName, string expectedPerm
}
}

[Fact]
[PlatformSpecific(TestPlatforms.AnyUnix & ~TestPlatforms.Browser)]
public async Task CanZipNamedPipe()
{
string destPath = Path.Combine(TestDirectory, "dest.zip");

string subFolderPath = Path.Combine(TestDirectory, "subfolder");
string fifoPath = Path.Combine(subFolderPath, "namedPipe");
Directory.CreateDirectory(subFolderPath); // mandatory before calling mkfifo
Assert.Equal(0, mkfifo(fifoPath, 438 /* 666 in octal */));

byte[] contentBytes = { 1, 2, 3, 4, 5 };

await Task.WhenAll(
Task.Run(() =>
{
using FileStream fs = new (fifoPath, FileMode.Open, FileAccess.Write, FileShare.Read);
foreach (byte content in contentBytes)
{
fs.WriteByte(content);
}
}),
Task.Run(() =>
{
ZipFile.CreateFromDirectory(subFolderPath, destPath);

using ZipArchive zippedFolder = ZipFile.OpenRead(destPath);
using Stream unzippedPipe = zippedFolder.Entries.Single().Open();

byte[] readBytes = new byte[contentBytes.Length];
Assert.Equal(contentBytes.Length, unzippedPipe.Read(readBytes));
Assert.Equal<byte>(contentBytes, readBytes);
Assert.Equal(0, unzippedPipe.Read(readBytes)); // EOF
}));
}

private static string GetExpectedPermissions(string expectedPermissions)
{
if (string.IsNullOrEmpty(expectedPermissions))
Expand All @@ -156,5 +195,8 @@ private static string GetExpectedPermissions(string expectedPermissions)

return expectedPermissions;
}

[DllImport("libc", SetLastError = true)]
private static extern int mkfifo(string path, int mode);
}
}