1

I was trying to write a powershell script to unzip gziped files. This scripts works perfectly on small files, on larger files (dozen MBs of unzipped size) it is producing an incomplete result.

PSVersion 4.0
WSManStackVersion 3.0
SerializationVersion 1.1.0.1
CLRVersion 4.0.30319.18052
BuildVersion 6.3.9600.16406
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0}
PSRemotingProtocolVersion 2.2

There is no error raised, and it just looks like the scripts completes smoothly. When unzipping with 7z the file is complete. Any idea why this might be happening?

$infile = "somefile.gz"
$outfile = ($infile -replace '\.gz$','.xml')

$input = New-Object System.IO.FileStream $inFile, ([IO.FileMode]::Open), ([IO.FileAccess]::Read), ([IO.FileShare]::Read)
$output = New-Object System.IO.FileStream $outFile, ([IO.FileMode]::Create), ([IO.FileAccess]::Write), ([IO.FileShare]::None)
$gzipStream = New-Object System.IO.Compression.GzipStream $input, ([IO.Compression.CompressionMode]::Decompress), true

$buffer = New-Object byte[](0x1000)

while(($read = $gzipstream.Read($buffer, 0, $buffer.Length)) -gt 0){
       $output.Write($buffer, 0, $read)
    }

$gzipStream.Close()
$output.Close()
$input.Close()
Jan
  • 437
  • 4
  • 15
  • This problem seems to be identical to this thread http://stackoverflow.com/questions/1590846/net-gzipstream-compress-and-decompress-problem unfortunatelly any suggeston listed there did not fix it. – Jan Mar 16 '14 at 15:06

0 Answers0