Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Example working code to decompress a file with an extension of "tar.gz". ie Uncompress (expand) a sample
- # file such as: filename.tar.gz.
- # Admittedly, there are better ways of writing this code more succinctly but using the layout given, it will
- # remind me of how this task is done. I don't expand 'tar.gz' files very often so I needed a writing style
- # which would be a good reminder of how to do this in the future.
- #
- $srcfile = 'C:\Test\filename.tar.gz';
- $destfile = 'C:\Test\sampledata.dat';
- $path = $srcfile;
- $mode = [System.IO.FileMode]::Open;
- $access = [System.IO.FileAccess]::Read;
- $share = [System.IO.FileShare]::Read;
- $fis = New-Object -typeName 'System.IO.FileStream' -ArgumentList `
- $path, $mode, $access, $share;
- $path = $destfile;
- $mode = [System.IO.FileMode]::Create;
- $access = [System.IO.FileAccess]::Write;
- $share = [System.IO.FileShare]::None;
- $fos = New-Object -typeName 'System.IO.FileStream' -ArgumentList `
- $path, $mode, $access, $share;
- $stream = $fis;
- $mode = [System.IO.Compression.CompressionMode]::Decompress;
- $gzipStream = New-Object -typeName 'System.IO.Compression.GzipStream' -ArgumentList `
- $stream, $mode;
- $databuffer = New-Object Byte[] 4KB;
- $bytesRead = -1;
- do {
- $bytesRead = $gzipstream.Read($databuffer, 0, $databuffer.Length)
- $fos.Write($databuffer, 0, $bytesRead)
- } while ($bytesRead -gt 0)
- $gzipStream.Dispose();
- $fos.Dispose();
- $fis.Dispose();
- # Have a quick look at the files we've been dealing with.
- Get-ChildItem $srcfile, $destfile;
Add Comment
Please, Sign In to add comment