문제

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()

올바른 솔루션이 없습니다

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top