Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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