Last active
February 24, 2021 16:31
-
-
Save lantrix/738ebfa616d5222a8b1db947793bc3fc to your computer and use it in GitHub Desktop.
Revisions
-
lantrix revised this gist
Jul 12, 2017 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -4,7 +4,8 @@ # Based upon post by Seth Jackson https://sethjackson.github.io/2016/12/17/path-separators/ # # PowerShell 5 (WMF5) & 6 # Using class Keyword https://msdn.microsoft.com/powershell/reference/5.1/Microsoft.PowerShell.Core/about/about_Classes # Add-Type -AssemblyName System.Text.Encoding @@ -24,6 +25,7 @@ class FixedEncoder : System.Text.UTF8Encoding { # # PowerShell 4 (WMF4) # Using Add-Type cmdlet https://msdn.microsoft.com/en-us/powershell/reference/4.0/microsoft.powershell.utility/add-type # Add-Type -AssemblyName System.Text.Encoding -
lantrix revised this gist
Jul 12, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -30,7 +30,7 @@ Add-Type -AssemblyName System.Text.Encoding Add-Type -AssemblyName System.IO.Compression.FileSystem $EncoderClass=@" public class FixedEncoder : System.Text.UTF8Encoding { public FixedEncoder() : base(true) { } public override byte[] GetBytes(string s) { -
lantrix created this gist
Jul 12, 2017 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,45 @@ # When using System.IO.Compression.ZipFile.CreateFromDirectory in PowerShell, it still uses backslashes in the zip paths # despite this https://docs.microsoft.com/en-us/dotnet/framework/migration-guide/mitigation-ziparchiveentry-fullname-path-separator # Based upon post by Seth Jackson https://sethjackson.github.io/2016/12/17/path-separators/ # # PowerShell 5 (WMF5) # Add-Type -AssemblyName System.Text.Encoding Add-Type -AssemblyName System.IO.Compression.FileSystem class FixedEncoder : System.Text.UTF8Encoding { FixedEncoder() : base($true) { } [byte[]] GetBytes([string] $s) { $s = $s.Replace("\\", "/"); return ([System.Text.UTF8Encoding]$this).GetBytes($s); } } [System.IO.Compression.ZipFile]::CreateFromDirectory($dirToZip, $zipFilePath, [System.IO.Compression.CompressionLevel]::Optimal, $false, [FixedEncoder]::new()) # # PowerShell 4 (WMF4) # Add-Type -AssemblyName System.Text.Encoding Add-Type -AssemblyName System.IO.Compression.FileSystem $EncoderClass=@" public class FixedEncoder : System.Text.UTF8Encoding { public FixedEncoder() : base(true) { } public override byte[] GetBytes(string s) { s = s.Replace("\\", "/"); return base.GetBytes(s); } } "@ Add-Type -TypeDefinition $EncoderClass $Encoder = New-Object FixedEncoder [System.IO.Compression.ZipFile]::CreateFromDirectory($dirToZip, $zipFilePath, [System.IO.Compression.CompressionLevel]::Optimal, $false, $Encoder)