Skip to content

Commit 05fadcc

Browse files
authored
Merge pull request #42 from santisq/41-add-zlib-deflate-etc-compression-decompression-support
Adds support for several compression algorithms
2 parents bac3a41 + 8e95c8b commit 05fadcc

106 files changed

Lines changed: 5693 additions & 2724 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,31 @@
11
# CHANGELOG
22

3+
## 06/23/2025
4+
5+
- Added commands supporting several algorithms to compress and decompress strings:
6+
- `ConvertFrom-BrotliString` & `ConvertTo-BrotliString` (using to BrotliSharpLib)
7+
- `ConvertFrom-DeflateString` & `ConvertTo-DeflateString` (from CLR)
8+
- `ConvertFrom-ZlibString` & `ConvertTo-ZlibString` (custom implementation)
9+
- Added commands for `.tar` entry management with a reduced set of operations compared to `zip` entry management:
10+
- `Get-TarEntry`: Lists entries, serving as the main entry point for `TarEntry` cmdlets.
11+
- `Get-TarEntryContent`: Retrieves the content of a tar entry.
12+
- `Expand-TarEntry`: Extracts a tar entry to a file.
13+
- Added commands to compress files and folders into `.tar` archives and extract `.tar` archives with various compression algorithms:
14+
- `Compress-TarArchive` & `Expand-TarArchive`: Supported compression algorithms include `gz`, `bz2`, `zst`, `lz`, and `none` (no compression).
15+
- Removed commands:
16+
- `Compress-GzipArchive` & `Expand-GzipArchive`: These were deprecated as they only supported single-file compression, which is now better handled by the module’s `.tar` archive functionality. For a workaround to compress or decompress single files using gzip, see [Example 2 in `ConvertTo-GzipString`][example2converttogzipstring], which demonstrates using:
17+
18+
```powershell
19+
[System.Convert]::ToBase64String([System.IO.File]::ReadAllBytes($path)) | ConvertFrom-GzipString
20+
```
21+
22+
This update was made possible by the following projects. If you find them helpful, please consider starring their repositories:
23+
24+
- [SharpZipLib](https://github.com/icsharpcode/SharpZipLib)
25+
- [SharpCompress](https://github.com/adamhathcock/sharpcompress)
26+
- [BrotliSharpLib](https://github.com/master131/BrotliSharpLib)
27+
- [ZstdSharp](https://github.com/oleg-st/ZstdSharp)
28+
329
## 01/10/2025
430
531
- Code improvements.
@@ -38,3 +64,5 @@
3864
- Moved from `[PSCompression.ZipEntryExtensions]::NormalizePath` to `[PSCompression.Extensions.PathExtensions]::NormalizePath`.
3965
- `Get-ZipEntry` command:
4066
- Renamed Parameter `-EntryType` to `-Type`.
67+
68+
[example2converttogzipstring]: https://github.com/santisq/PSCompression/blob/main/docs/en-US/ConvertTo-GzipString.md#example-2-create-a-gzip-compressed-file-from-a-string

README.md

Lines changed: 150 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<h1 align="center">PSCompression</h1>
22
<div align="center">
3-
<sub>Zip and GZip utilities for PowerShell</sub>
3+
<sub>Zip, tar, and string compression utilities for PowerShell!</sub>
44
<br/><br/>
55

66
[![build](https://github.com/santisq/PSCompression/actions/workflows/ci.yml/badge.svg)](https://github.com/santisq/PSCompression/actions/workflows/ci.yml)
@@ -11,157 +11,156 @@
1111

1212
</div>
1313

14-
PSCompression is a PowerShell Module that provides Zip and Gzip utilities for compression, expansion and management. It also solves a few issues with Zip compression existing in _built-in PowerShell_.
14+
`PSCompression` is a PowerShell module that provides utilities for creating, managing, and extracting zip and tar archives, as well as compressing and decompressing strings. It overcomes limitations in built-in PowerShell archive cmdlets (e.g., 2 GB zip file limits) and supports multiple compression algorithms, including gzip, bzip2, Zstandard, lzip, Brotli, Deflate, and Zlib. Built for cross-platform use, it’s compatible with Windows, Linux, and macOS.
1515

16-
## What does this Module offer?
16+
## Features
1717

18-
### Zip Cmdlets
18+
- __Zip Archive Management__: Create, list, extract, retrieve content, modify, and remove entries in zip archives with pipeline support.
19+
- __Tar Archive Management__: Compress and extract tar archives with support for `gz`, `bz2`, `zst`, `lz`, and uncompressed (`none`) formats.
20+
- __Tar Entry Management__: List, extract, and retrieve content from individual tar entries.
21+
- __String Compression__: Compress and decompress strings using Brotli, Deflate, Gzip, and Zlib algorithms.
1922

20-
<div class="zipcmdlets">
21-
<table>
22-
<tr>
23-
<th>Cmdlet</th>
24-
<th>Description</th>
25-
</tr>
26-
<tr>
27-
<td colspan="1" width="230" height="60">
28-
29-
[`Get-ZipEntry`](docs/en-US/Get-ZipEntry.md)
30-
31-
</td>
32-
<td>
33-
34-
Main entry point for the `*-ZipEntry` cmdlets in this module. It can list zip archive entries from specified paths or input stream.
35-
36-
</td>
37-
</tr>
38-
<tr>
39-
<td colspan="1" width="230" height="60">
40-
41-
[`Expand-ZipEntry`](docs/en-US/Expand-ZipEntry.md)
42-
43-
</td>
44-
<td>
45-
46-
Expands zip entries to a destination directory.
47-
48-
</td>
49-
</tr>
50-
<tr>
51-
<td colspan="1" width="230" height="60">
52-
53-
[`Get-ZipEntryContent`](docs/en-US/Get-ZipEntryContent.md)
54-
55-
</td>
56-
<td>
57-
58-
Gets the content of one or more zip entries.
59-
60-
</td>
61-
</tr>
62-
<tr>
63-
<td colspan="1" width="230" height="60">
64-
65-
[`New-ZipEntry`](docs/en-US/New-ZipEntry.md)
66-
67-
</td>
68-
<td>Creates zip entries from specified path or paths.</td>
69-
</tr>
70-
<tr>
71-
<td colspan="1" width="230" height="60">
72-
73-
[`Remove-ZipEntry`](docs/en-US/Remove-ZipEntry.md)
74-
75-
</td>
76-
<td>Removes zip entries from one or more zip archives.</td>
77-
</tr>
78-
<tr>
79-
<td colspan="1" width="230" height="60">
80-
81-
[`Rename-ZipEntry`](docs/en-US/Rename-ZipEntry.md)
82-
83-
</td>
84-
<td>Renames zip entries from one or more zip archives.</td>
85-
</tr>
86-
<tr>
87-
<td colspan="1" width="230" height="60">
88-
89-
[`Set-ZipEntryContent`](docs/en-US/Set-ZipEntryContent.md)
90-
91-
</td>
92-
<td>Sets or appends content to a zip entry.</td>
93-
</tr>
94-
<tr>
95-
<td colspan="1" width="230" height="60">
23+
# Cmdlets
9624

97-
[`Compress-ZipArchive`](docs/en-US/Compress-ZipArchive.md)
25+
## Cmdlets
9826

99-
</td>
100-
<td>
27+
### Zip Archive Cmdlets
10128

102-
Similar capabilities as
103-
[`Compress-Archive`](docs/en-US/https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.archive/compress-archive?view=powershell-7.2)
104-
and overcomes a few issues with the built-in cmdlet (2 GB limit and more).
105-
106-
</td>
107-
</tr>
29+
<table>
30+
<tr>
31+
<th>Cmdlet</th>
32+
<th>Alias</th>
33+
<th>Description</th>
34+
</tr>
35+
<tr>
36+
<td colspan="1" width="220"><a href="docs/en-US/Compress-ZipArchive.md">Compress-ZipArchive</a></td>
37+
<td><code>zipcompress</code></td>
38+
<td>Compresses files and folders into a zip archive, overcoming built-in PowerShell limitations.</td>
39+
</tr>
40+
<tr>
41+
<td><a href="docs/en-US/Expand-ZipEntry.md">Expand-ZipEntry</a></td>
42+
<td><code>unzipentry</code></td>
43+
<td>Extracts individual zip entries to a destination directory.</td>
44+
</tr>
45+
<tr>
46+
<td><a href="docs/en-US/Get-ZipEntry.md">Get-ZipEntry</a></td>
47+
<td><code>zipge</code></td>
48+
<td>Lists zip archive entries from paths or streams, serving as the entry point for zip cmdlets.</td>
49+
</tr>
50+
<tr>
51+
<td><a href="docs/en-US/Get-ZipEntryContent.md">Get-ZipEntryContent</a></td>
52+
<td><code>zipgec</code></td>
53+
<td>Retrieves the content of zip entries as text or bytes.</td>
54+
</tr>
55+
<tr>
56+
<td><a href="docs/en-US/New-ZipEntry.md">New-ZipEntry</a></td>
57+
<td><code>zipne</code></td>
58+
<td>Adds new entries to a zip archive from files or paths.</td>
59+
</tr>
60+
<tr>
61+
<td><a href="docs/en-US/Remove-ZipEntry.md">Remove-ZipEntry</a></td>
62+
<td><code>ziprm</code></td>
63+
<td>Removes entries from one or more zip archives.</td>
64+
</tr>
65+
<tr>
66+
<td><a href="docs/en-US/Rename-ZipEntry.md">Rename-ZipEntry</a></td>
67+
<td><code>zipren</code></td>
68+
<td>Renames entries in one or more zip archives.</td>
69+
</tr>
70+
<tr>
71+
<td><a href="docs/en-US/Set-ZipEntryContent.md">Set-ZipEntryContent</a></td>
72+
<td><code>zipsc</code></td>
73+
<td>Sets or appends content to a zip entry.</td>
74+
</tr>
10875
</table>
109-
</div>
11076

111-
### Gzip Cmdlets
77+
### Tar Archive Cmdlets
11278

113-
<div class="gzipcmdlets">
11479
<table>
115-
<tr>
116-
<th>Cmdlet</th>
117-
<th>Description</th>
118-
</tr>
119-
<tr>
120-
<td colspan="1" width="230" height="60">
121-
122-
[`Compress-GzipArchive`](docs/en-US/Compress-GzipArchive.md)
123-
124-
</td>
125-
<td>
126-
Can compress one or more specified file paths into a Gzip file.
127-
</td>
128-
</tr>
129-
<tr>
130-
<td colspan="1" width="230" height="60">
131-
132-
[`ConvertFrom-GzipString`](docs/en-US/ConvertFrom-GzipString.md)
133-
134-
</td>
135-
<td>
136-
Expands Gzip Base64 input strings.
137-
</td>
138-
</tr>
139-
140-
<tr>
141-
<td colspan="1" width="230" height="60">
142-
143-
[`ConvertTo-GzipString`](docs/en-US/ConvertTo-GzipString.md)
144-
145-
</td>
146-
<td>
147-
Can compress input strings into Gzip Base64 strings or raw bytes.
148-
</td>
149-
</tr>
150-
151-
<tr>
152-
<td colspan="1" width="230" height="60">
153-
154-
[`Expand-GzipArchive`](docs/en-US/Expand-GzipArchive.md)
155-
156-
</td>
157-
<td>
80+
<tr>
81+
<th>Cmdlet</th>
82+
<th>Alias</th>
83+
<th>Description</th>
84+
</tr>
85+
<tr>
86+
<td colspan="1" width="220"><a href="docs/en-US/Compress-TarArchive.md">Compress-TarArchive</a></td>
87+
<td><code>tarcompress</code></td>
88+
<td>Compresses files and folders into a tar archive with optional compression (gz, bz2, zst, lz, none).</td>
89+
</tr>
90+
<tr>
91+
<td><a href="docs/en-US/Expand-TarArchive.md">Expand-TarArchive</a></td>
92+
<td><code>untar</code></td>
93+
<td>Extracts a tar archive with support for gz, bz2, zst, lz, and uncompressed formats.</td>
94+
</tr>
95+
<tr>
96+
<td><a href="docs/en-US/Expand-TarEntry.md">Expand-TarEntry</a></td>
97+
<td><code>untarentry</code></td>
98+
<td>Extracts individual tar entries to a destination directory.</td>
99+
</tr>
100+
<tr>
101+
<td><a href="docs/en-US/Get-TarEntry.md">Get-TarEntry</a></td>
102+
<td><code>targe</code></td>
103+
<td>Lists tar archive entries from paths or streams, serving as the entry point for tar cmdlets.</td>
104+
</tr>
105+
<tr>
106+
<td><a href="docs/en-US/Get-TarEntryContent.md">Get-TarEntryContent</a></td>
107+
<td><code>targc</code></td>
108+
<td>Retrieves the content of tar entries as text or bytes.</td>
109+
</tr>
110+
</table>
158111

159-
Expands Gzip compressed files to a destination path or to the [success stream](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_output_streams?view=powershell-7.3#success-stream).
112+
### String Compression Cmdlets
160113

161-
</td>
162-
</tr>
114+
<table>
115+
<tr>
116+
<th>Cmdlet</th>
117+
<th>Alias</th>
118+
<th>Description</th>
119+
</tr>
120+
<tr>
121+
<td colspan="1" width="220"><a href="docs/en-US/ConvertFrom-BrotliString.md">ConvertFrom-BrotliString</a></td>
122+
<td><code>frombrotlistring</code></td>
123+
<td>Decompresses a Brotli-compressed string.</td>
124+
</tr>
125+
<tr>
126+
<td><a href="docs/en-US/ConvertFrom-DeflateString.md">ConvertFrom-DeflateString</a></td>
127+
<td><code>fromdeflatestring</code></td>
128+
<td>Decompresses a Deflate-compressed string.</td>
129+
</tr>
130+
<tr>
131+
<td><a href="docs/en-US/ConvertFrom-GzipString">ConvertFrom-GzipString</a></td>
132+
<td><code>fromgzipstring</code></td>
133+
<td>Decompresses a Gzip-compressed string.</td>
134+
</tr>
135+
<tr>
136+
<td><a href="docs/en-US/ConvertFrom-ZlibString.md">ConvertFrom-ZlibString</a></td>
137+
<td><code>fromzlibstring</code></td>
138+
<td>Decompresses a Zlib-compressed string.</td>
139+
</tr>
140+
<tr>
141+
<td><a href="docs/en-US/ConvertTo-BrotliString.md">ConvertTo-BrotliString</a></td>
142+
<td><code>tobrotlistring</code></td>
143+
<td>Compresses a string using Brotli.</td>
144+
</tr>
145+
<tr>
146+
<td><a href="docs/en-US/ConvertTo-DeflateString.md">ConvertTo-DeflateString</a></td>
147+
<td><code>todeflatestring</code></td>
148+
<td>Compresses a string using Deflate.</td>
149+
</tr>
150+
<tr>
151+
<td><a href="docs/en-US/ConvertTo-GzipString.md">ConvertTo-GzipString</a></td>
152+
<td><code>togzipstring</code></td>
153+
<td>Compresses a string using Gzip to Base64 or raw bytes.</td>
154+
</tr>
155+
<tr>
156+
<td><a href="docs/en-US/ConvertTo-ZlibString.md">ConvertTo-ZlibString</a></td>
157+
<td><code>tozlibstring</code></td>
158+
<td>Compresses a string using Zlib.</td>
159+
</tr>
163160
</table>
164-
</div>
161+
162+
> [!NOTE]
163+
> The `Compress-GzipArchive` and `Expand-GzipArchive` cmdlets have been removed, as their single-file gzip functionality is now handled by `Compress-TarArchive` and `Expand-TarArchive`. For a workaround to compress or decompress single files using gzip, see [Example 2 in `ConvertTo-GzipString`](./docs/en-US/ConvertTo-GzipString.md#example-2-create-a-gzip-compressed-file-from-a-string).
165164
166165
## Documentation
167166

@@ -189,6 +188,18 @@ Set-Location ./PSCompression
189188

190189
This module has no external requirements and is compatible with __Windows PowerShell 5.1__ and [__PowerShell 7+__](https://github.com/PowerShell/PowerShell).
191190

191+
## Acknowledgments
192+
193+
This module is powered by the following open-source projects:
194+
195+
- [SharpZipLib](https://github.com/icsharpcode/SharpZipLib)
196+
- [SharpCompress](https://github.com/adamhathcock/sharpcompress)
197+
- [BrotliSharpLib](https://github.com/master131/BrotliSharpLib)
198+
- [ZstdSharp](https://github.com/oleg-st/ZstdSharp)
199+
- [System.IO.Compression](https://learn.microsoft.com/en-us/dotnet/api/system.io.compression)
200+
201+
If you find these projects helpful, consider starring their repositories!
202+
192203
## Contributing
193204

194205
Contributions are more than welcome, if you wish to contribute, fork this repository and submit a pull request with the changes.

build.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ if (-not ('ProjectBuilder.ProjectInfo' -as [type])) {
3838
}
3939
}
4040

41-
$projectInfo = [ProjectBuilder.ProjectInfo]::Create($PSScriptRoot, $Configuration)
41+
$projectInfo = [ProjectBuilder.ProjectInfo]::Create($PSScriptRoot, $Configuration, $PSVersionTable.PSVersion)
4242
$projectInfo.GetRequirements() | Import-Module -DisableNameChecking -Force
4343

4444
$ErrorActionPreference = $prev

0 commit comments

Comments
 (0)