File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed
Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change 1+ function ConvertFrom-Gzip {
2+ Param (
3+ [Parameter (Mandatory = $true , ValueFromPipeline = $true )]
4+ [ValidateScript ( { (Get-Item $_ ).Name.EndsWith(" .gz" ) })]
5+ [System.IO.FileInfo ]
6+ $InputObject ,
7+
8+ [Parameter (Mandatory = $false )]
9+ [switch ]
10+ $RemoveInputFile
11+ )
12+ Process {
13+ # Create a new file and open a filestream for it
14+ $NewFilename = $InputObject.FullName.Remove ($InputObject.FullName.Length - $InputObject.Extension.Length )
15+ $DecompressedFileStream = [System.IO.File ]::Create($NewFilename )
16+
17+ # Open the compressed file and copy the file to the decompressed stream
18+ $CompressedFileStream = $InputObject.OpenRead ()
19+ $GZipStream = [System.IO.Compression.GZipStream ]::new($CompressedFileStream , [System.IO.Compression.CompressionMode ]::Decompress)
20+ $GZipStream.CopyTo ($DecompressedFileStream )
21+
22+ # Cleanup
23+ $DecompressedFileStream.Dispose ()
24+ $GZipStream.Dispose ()
25+ $CompressedFileStream.Dispose ()
26+ $DecompressedFileStream , $GZipStream , $CompressedFileStream = $null
27+
28+ # Remove the initial file if requested.
29+ if ($PSBoundParameters.ContainsKey (' RemoveInputFile' )) {
30+ $InputObject.Delete ()
31+ }
32+ }
33+ }
You can’t perform that action at this time.
0 commit comments