| external help file | PSCompression.dll-Help.xml |
|---|---|
| Module Name | PSCompression |
| online version | https://github.com/santisq/PSCompression |
| schema | 2.0.0 |
Sets or appends content to an existing zip file entry.
Set-ZipEntryContent
-Value <Object[]>
[-SourceEntry] <ZipEntryFile>
[-Encoding <Encoding>]
[-Append]
[-PassThru]
[<CommonParameters>]Set-ZipEntryContent
-Value <Object[]>
[-SourceEntry] <ZipEntryFile>
[-AsByteStream]
[-Append]
[-BufferSize <Int32>]
[-PassThru]
[<CommonParameters>]The Set-ZipEntryContent cmdlet writes or appends content to a ZipEntryFile object produced by Get-ZipEntry or New-ZipEntry. By default, it replaces existing content; use -Append to add to it. Content can be text (strings) or raw bytes (via -AsByteStream). Input can be piped or provided via -Value.
To create a new entry, use New-ZipEntry.
Note
Due to a .NET limitation, writing or appending content larger than 2 GB to an existing zip entry may fail. To handle such content, recreate the zip archive or use tools like 7-Zip. See issue #19 for details.
PS ..pwsh\> $entry = New-ZipEntry .\test.zip -EntryPath test\helloworld.txt
PS ..pwsh\> 'hello', 'world', '!' | Set-ZipEntryContent $entry
PS ..pwsh\> $entry | Get-ZipEntryContent
hello
world
!This example creates a new file entry and pipes strings to set its content (replacing any existing data).
PS ..pwsh\> Set-ZipEntryContent $entry -Value 'hello', 'world', '!' -Append
PS ..pwsh\> $entry | Get-ZipEntryContent
hello
world
!
hello
world
!This example appends additional strings to the existing entry content using -Append.
PS ..pwsh\> $entry = Get-ZipEntry .\test.zip -Include test/helloworld.txt
PS ..pwsh\> $bytes = [System.Text.Encoding]::UTF8.GetBytes('hello world!')
PS ..pwsh\> $bytes | Set-ZipEntryContent $entry -AsByteStream
PS ..pwsh\> $entry | Get-ZipEntryContent
hello world!This example appends the same byte array to the entry using -AsByteStream and -Append.
PS ..pwsh\> $bytes | Set-ZipEntryContent $entry -AsByteStream -Append
PS ..pwsh\> $entry | Get-ZipEntryContent
hello world!hello world!Using the same byte array in the previous example, we can append bytes to the entry stream.
Appends the content to the zip entry instead of overwriting it.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: FalseSpecifies that the content should be written as a stream of bytes.
Type: SwitchParameter
Parameter Sets: ByteStream
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: FalseFor efficiency purposes this cmdlet buffers bytes before writing them to the Zip Archive Entry. This parameter determines how many bytes are buffered before being written to the stream.
Note
- This parameter applies only when
-AsByteStreamis used. - The default buffer size is 128 KiB.
Type: Int32
Parameter Sets: ByteStream
Aliases:
Required: False
Position: Named
Default value: 128000
Accept pipeline input: False
Accept wildcard characters: FalseThe character encoding used to read the entry content.
Note
- This parameter applies only when
-AsByteStreamis not used. - The default encoding is UTF-8 without BOM.
Type: Encoding
Parameter Sets: StringValue
Aliases:
Required: False
Position: Named
Default value: utf8NoBOM
Accept pipeline input: False
Accept wildcard characters: FalseOutputs the updated ZipEntryFile object. By default, the cmdlet produces no output.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: FalseSpecifies the zip archive entry that receives the content. ZipEntryFile instances can be obtained using Get-ZipEntry or New-ZipEntry cmdlets.
Type: ZipEntryFile
Parameter Sets: (All)
Aliases:
Required: True
Position: 0
Default value: None
Accept pipeline input: False
Accept wildcard characters: FalseSpecifies the new content for the zip entry.
Type: Object[]
Parameter Sets: (All)
Aliases:
Required: True
Position: Named
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: FalseThis cmdlet supports the common parameters. For more information, see about_CommonParameters.
You can pipe strings (for text content) or byte arrays (for binary content) to this cmdlet.
By default, this cmdlet produces no output.
When the -PassThru switch is used, the cmdlet outputs the updated ZipEntryFile object.