1

Internet is an amazing place to be, I found this code that allows me to inflate a tar.gz file to .tar:

Function DeGZip-File{
    Param(
        $infile,
        $outfile = ($infile -replace '\.gz$','')
        )
    $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)
    $buffer = New-Object byte[](1024)
    while($true){
        $read = $gzipstream.Read($buffer, 0, 1024)
        if ($read -le 0){break}
        $output.Write($buffer, 0, $read)
        }
    $gzipStream.Close()
    $output.Close()
    $input.Close()
}
DeGZip-File "C:\temp\maxmind\temp.tar.gz" "C:\temp\maxmind\temp.tar"

Now I have a .tar file in my hands. but how can I open that?

My goal is to extract directly from .tar.gz to file.

Mark Adler
  • 101,978
  • 13
  • 118
  • 158
Francesco Mantovani
  • 10,216
  • 13
  • 73
  • 113
  • 1
    A [tarball](https://en.wikipedia.org/wiki/Tar_(computing)) is extracted with a tool that's familiar with the format. There's one [in Win 10](https://stackoverflow.com/a/46876070/503046) since 2018. For older systems, use 3rd party tool. – vonPryz Sep 15 '21 at 10:01
  • Thank you @vonPryz . That link says that in any case I have to install `7Zip4PowerShell`. So Windows10 doesn't provide an out-of-the-box solution. It's always 3rd party tools – Francesco Mantovani Sep 15 '21 at 10:13
  • 2
    @FrancescoMantovani no [`tar.exe` and `curl.exe` is included in Windows 10 by default](https://learn.microsoft.com/en-us/virtualization/community/team-blog/2017/20171219-tar-and-curl-come-to-windows) since Build 17063. No need to install anything – phuclv Sep 15 '21 at 13:04
  • @phuclv , I withdraw what I just said – Francesco Mantovani Sep 15 '21 at 14:23
  • @phuclv , I have a problem with the tar the Windows 10 provides by default: I have a file of 1Gb that decompressed is 4Gb with just 1 beefy CSV inside and tar commands are not working on it: https://github.com/MicrosoftDocs/Virtualization-Documentation/issues/1656 The only solution is to download the Gzip library and that does everything in 1 minute. But the tar provided by Microsoft cannot deflate it – Francesco Mantovani Sep 15 '21 at 14:26
  • 1
    "deflate" is the wrong word. Deflate has nothing to do with tar, though is the verb for gzip _compression_ (not decompression). You should use "extract" for getting the files out of a tar stream. – Mark Adler Sep 15 '21 at 21:20

1 Answers1

3
Get-ChildItem -Path $InputPath -Filter "*.tar.gz" | 
Foreach-Object {
    tar -xvzf $_.FullName -C $OutputPath
}
user1
  • 86
  • 5