Last active
September 9, 2016 10:18
-
-
Save sergiorykov/adea852c0af245c6648777505f4a106f to your computer and use it in GitHub Desktop.
Create zip archive on Windows for Linux/Debian with valid file names
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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