Functions/Data/Convert-GzFile.ps1

Function Convert-GzFile
    {
    [CmdletBinding()]
    Param
        (
        # Path to File
        [Parameter(Mandatory=$True)]
        [String]
        $Path
        )

    Process
        {
        # Define Output path based on input
        $OutPath = $Path -replace '\.gz?',''
        
        # Test for presence of the input file
        if (Test-Path $Path)
            {
            # Create input and output streams for the file
            $input = New-Object System.IO.FileStream $Path, ([IO.FileMode]::Open), ([IO.FileAccess]::Read), ([IO.FileShare]::Read)
            $output = New-Object System.IO.FileStream $OutPath, ([IO.FileMode]::Create), ([IO.FileAccess]::Write), ([IO.FileShare]::None)
            
            # Create Decompression stream and buffer
            $gzipStream = New-Object System.IO.Compression.GzipStream $input, ([IO.Compression.CompressionMode]::Decompress)
            $buffer = New-Object byte[](1024)
            
            # Write streaming data from the decompression stream to the output stream
            $read = $gzipstream.Read($buffer, 0, 1024)
            if ($read -le 0){break}
            $output.Write($buffer, 0, $read)

            # Close create IO Streams
            $gzipStream.Close()
            $output.Close()
            $input.Close()
            } 
        }
    }