Skip to content

Instantly share code, notes, and snippets.

@MauRiEEZZZ
Created October 12, 2019 20:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MauRiEEZZZ/c2f3b4bb226f0ed9d421e7f6ad4857e9 to your computer and use it in GitHub Desktop.
Save MauRiEEZZZ/c2f3b4bb226f0ed9d421e7f6ad4857e9 to your computer and use it in GitHub Desktop.
Compress Byte Array
function Compress-ByteArray {
[CmdletBinding()]
Param (
[Parameter(Mandatory,ValueFromPipeline,ValueFromPipelineByPropertyName)]
[byte[]] $byteArray
)
Process {
[System.IO.MemoryStream] $inMemDataStream = New-Object System.IO.MemoryStream
$gzipInstance = New-Object System.IO.Compression.GzipStream $inMemDataStream, ([IO.Compression.CompressionMode]::Compress)
Write-Verbose -Message "Compressing..."
$gzipInstance.Write( $byteArray, 0, $byteArray.Length )
$gzipInstance.Close()
$inMemDataStream.Close()
[byte[]] $result = $inMemDataStream.ToArray()
return Write-Output -NoEnumerate $result
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment