| external help file | PSCompression.dll-Help.xml |
|---|---|
| Module Name | PSCompression |
| online version | https://github.com/santisq/PSCompression |
| schema | 2.0.0 |
Retrieves the content of one or more file entries from a tar archive.
Get-TarEntryContent
-Entry <TarEntryFile[]>
[-Encoding <Encoding>]
[-Raw]
[<CommonParameters>]Get-TarEntryContent
-Entry <TarEntryFile[]>
[-Raw]
[-AsByteStream]
[-BufferSize <Int32>]
[<CommonParameters>]The Get-TarEntryContent cmdlet retrieves the content of TarEntryFile objects produced by Get-TarEntry. This cmdlet supports text output (line-by-line or raw string) and binary output (byte arrays or streams).
Tip
Entries output by Get-TarEntry can be piped to this cmdlet.
PS C:\> Get-TarEntry .\archive.tar -Include folder1/file1.txt | Get-TarEntryContentThis example retrieves the text content of a specific file entry from a tar archive. By default, content is streamed line by line (as an array of strings).
PS C:\> Get-TarEntry .\archive.tar -Include folder1/file1.txt | Get-TarEntryContent -RawThis example retrieves the entire text content as a single multi-line string using the -Raw switch.
PS C:\> $bytes = Get-TarEntry .\archive.tar -Include folder1/helloworld.txt | Get-TarEntryContent -AsByteStream
PS C:\> [System.Text.Encoding]::UTF8.GetString($bytes)
hello world!This example retrieves the raw bytes of a file entry as a byte array using -AsByteStream, then converts them to a string.
PS C:\> $bytes = Get-TarEntry .\archive.tar.gz -Algorithm gz -Include *.md | Get-TarEntryContent -AsByteStream -Raw
PS C:\> $bytes[0].GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True Byte[] System.Array
PS C:\> $bytes[1].Length
7767This example retrieves the raw bytes of all .md files as an array of byte[] objects (one per entry) using -AsByteStream and -Raw.
PS C:\> $stream = Invoke-WebRequest https://example.com/archive.tar.gz
PS C:\> $stream | Get-TarEntry -Include readme.md -Algorithm gz | Get-TarEntryContent -RawThis example retrieves the content of readme.md from a gzip-compressed tar archive streamed from the web.
Note
When Get-TarEntry processes a stream, it defaults to the gz (gzip) algorithm. Specify -Algorithm (e.g., -Algorithm bz2 for bzip2) to match the compression type, or an error may occur if the stream is not gzip-compressed.
Specifies that the content should be read as a stream of bytes.
Type: SwitchParameter
Parameter Sets: Bytes
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: FalseDetermines the number of bytes read into the buffer before outputting the stream of bytes. This parameter applies only when -Raw is not used. The default buffer size is 128 KiB.
Type: Int32
Parameter Sets: Bytes
Aliases:
Required: False
Position: Named
Default value: 128000
Accept pipeline input: False
Accept wildcard characters: FalseSpecifies the character encoding used to read the entry content. . The default encoding is utf8NoBOM.
Note
- This parameter applies only when
-AsByteStreamis not used. - The default encoding is UTF-8 without BOM.
Type: Encoding
Parameter Sets: Stream
Aliases:
Required: False
Position: Named
Default value: utf8NoBOM
Accept pipeline input: False
Accept wildcard characters: FalseThe tar entry or entries to get the content from. This parameter is designed to accept pipeline input from Get-TarEntry but can also be used as a named parameter.
Type: TarEntryFile[]
Parameter Sets: (All)
Aliases:
Required: True
Position: Named
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: FalseBy default, the cmdlet outputs text content as an array of strings (split on newlines). The -Raw switch returns the entire content as a single string with newlines preserved.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: FalseThis cmdlet supports the common parameters. For more information, see about_CommonParameters.
You can pipe one or more TarEntryFile objects produced by Get-TarEntry to this cmdlet.
By default, this cmdlet returns the content as an array of strings, one per line. When the -Raw parameter is used, it returns a single string.
- When the
-AsByteStreamparameter is used, this cmdlet returns the content as a byte array (System.Byte[]). - When
-AsByteStreamand-Raware combined, it returns an array of byte arrays (one per entry).