external help file | Module Name | online version | schema |
---|---|---|---|
PSCompression.dll-Help.xml |
PSCompression |
2.0.0 |
Gets the content of a zip entry.
Get-ZipEntryContent
-ZipEntry <ZipEntryFile[]>
[-Encoding <Encoding>]
[-Raw]
[<CommonParameters>]
Get-ZipEntryContent
-ZipEntry <ZipEntryFile[]>
[-Raw]
[-AsByteStream]
[-BufferSize <Int32>]
[<CommonParameters>]
The Get-ZipEntryContent
cmdlet gets the content of one or more ZipEntryFile
instances.
This cmdlet is meant to be used with Get-ZipEntry
as your entry point.
Tip
Entries outputted by Get-ZipEntry
can be piped to this cmdlet.
PS ..pwsh\> Get-ZipEntry .\myZip.zip -Include myrelative/entry.txt | Get-ZipEntryContent
-Include
parameter from Get-ZipEntry
can be used to target a specific entry by passing the entry's relative path, from there the output can be piped directly to Get-ZipEntryContent
.
By default, the cmdlet streams line-by-line .
PS ..pwsh\> Get-ZipEntry .\myZip.zip -Include myrelative/entry.txt | Get-ZipEntryContent -Raw
The cmdlet outputs a single multi-line string when the -Raw
switch is used instead of line-by-line streaming.
PS ..pwsh\> $bytes = Get-ZipEntry .\test.zip -Include test/helloworld.txt | Get-ZipEntryContent -AsByteStream
PS ..pwsh\> $bytes
104
101
108
108
111
32
119
111
114
108
100
33
13
10
PS ..pwsh\> [System.Text.Encoding]::UTF8.GetString($bytes)
hello world!
The -AsByteStream
switch can be useful to read non-text zip entries.
PS ..pwsh\> $bytes = Get-ZipEntry .\test.zip -Include *.md | Get-ZipEntryContent -AsByteStream -Raw
PS ..pwsh\> $bytes[0].GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True Byte[] System.Array
PS ..pwsh\> $bytes[1].Length
7767
When the -Raw
and -AsByteStream
switches are used together the cmdlet outputs byte[]
as single objects for each zip entry.
PS ..\pwsh> $package = Invoke-WebRequest https://www.powershellgallery.com/api/v2/package/PSCompression
PS ..\pwsh> $package | Get-ZipEntry -Include *.psd1 | Get-ZipEntryContent -Raw | Invoke-Expression
Name Value
---- -----
PowerShellVersion 5.1
Description Zip and GZip utilities for PowerShell!
RootModule bin/netstandard2.0/PSCompression.dll
FormatsToProcess {PSCompression.Format.ps1xml}
VariablesToExport {}
PrivateData {[PSData, System.Collections.Hashtable]}
CmdletsToExport {Get-ZipEntry, Get-ZipEntryContent, Set-ZipEntryContent, Remove-ZipEntry…}
ModuleVersion 2.0.10
Author Santiago Squarzon
CompanyName Unknown
GUID c63aa90e-ae64-4ae1-b1c8-456e0d13967e
FunctionsToExport {}
RequiredAssemblies {System.IO.Compression, System.IO.Compression.FileSystem}
Copyright (c) Santiago Squarzon. All rights reserved.
AliasesToExport {gziptofile, gzipfromfile, gziptostring, gzipfromstring…}
This parameter determines the total number of bytes read into the buffer before outputting the stream of bytes. This parameter is applicable only when -Raw
is not used. The buffer default value is 128 KiB.
Type: Int32
Parameter Sets: Bytes
Aliases:
Required: False
Position: Named
Default value: 128000
Accept pipeline input: False
Accept wildcard characters: False
The character encoding used to read the entry content.
Note
- This parameter is applicable only when
-AsByteStream
is not used. - The default encoding is
utf8NoBOM
.
Type: Encoding
Parameter Sets: Stream
Aliases:
Required: False
Position: Named
Default value: utf8NoBOM
Accept pipeline input: False
Accept wildcard characters: False
Ignores newline characters and returns the entire contents of an entry in one string with the newlines preserved. By default, newline characters in a file are used as delimiters to separate the input into an array of strings.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
The entry or entries to get the content from. This parameter can be and is meant to be bound from pipeline however can be also used as a named parameter.
Type: ZipEntryFile[]
Parameter Sets: (All)
Aliases:
Required: True
Position: Named
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: False
Specifies that the content should be read as a stream of bytes.
Type: SwitchParameter
Parameter Sets: Bytes
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
This cmdlet supports the common parameters. See about_CommonParameters.
You can pipe instances of ZipEntryFile
to this cmdlet. These instances are produced by Get-ZipEntry
and New-ZipEntry
cmdlets.
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.
This cmdlet returns the content as bytes when the -AsByteStream
parameter is used.