Skip to content

Instantly share code, notes, and snippets.

@OlivierLaflamme
Created August 27, 2021 05:44
Show Gist options
  • Save OlivierLaflamme/18829b49beae7f2b778ed727da948fcf to your computer and use it in GitHub Desktop.
Save OlivierLaflamme/18829b49beae7f2b778ed727da948fcf to your computer and use it in GitHub Desktop.
PowerShell compression \ decompression. I manage to get 50% decreasse on a small input stream.
Compression:
$s = @'YourInputHere"@
$ms = New-Object System.IO.MemoryStream
$cs = New-Object System.IO.Compression.GZipStream($ms, [System.IO.Compression.CompressionMode]::Compress)
$sw = New-Object System.IO.StreamWriter($cs)
$sw.Write($s)
$sw.Close();
$s = [System.Convert]::ToBase64String($ms.ToArray())
Decompression:
$data = [System.Convert]::FromBase64String("CompressedBase64StreamHere")
$ms = New-Object System.IO.MemoryStream
$ms.Write($data, 0, $data.Length)
$ms.Seek(0,0) | Out-Null
$sr = New-Object System.IO.StreamReader(New-Object System.IO.Compression.GZipStream($ms, [System.IO.Compression.CompressionMode]::Decompress))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment