Skip to content

Instantly share code, notes, and snippets.

@sergiorykov
Last active September 9, 2016 10:18
Show Gist options
  • Save sergiorykov/adea852c0af245c6648777505f4a106f to your computer and use it in GitHub Desktop.
Save sergiorykov/adea852c0af245c6648777505f4a106f to your computer and use it in GitHub Desktop.
Create zip archive on Windows for Linux/Debian with valid file names
using System.IO.Compression;
using System.Text;
namespace Mojito.Core.FileSystem
{
public static class UnixZipFile
{
public static void CreateFromDirectory(string sourceDirectoryName, string destinationArchiveFileName)
{
// http://stackoverflow.com/questions/27289115/system-io-compression-zipfile-net-4-5-output-zip-in-not-suitable-for-linux-mac
ZipFile.CreateFromDirectory(
sourceDirectoryName, destinationArchiveFileName, CompressionLevel.Optimal, false, new UnixNameUtf8Encoder());
}
private class UnixNameUtf8Encoder : UTF8Encoding
{
public override byte[] GetBytes(string s)
{
s = s.Replace("\\", "/");
return base.GetBytes(s);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment