Skip to content

Commit 5f04c93

Browse files
Merge pull request #7 from PoshWeb/zippy-skippy
Zippy 0.1
2 parents a8c644b + 3a704e4 commit 5f04c93

12 files changed

Lines changed: 1234 additions & 1 deletion

‎.github/workflows/build.yml‎

Lines changed: 494 additions & 0 deletions
Large diffs are not rendered by default.

‎Build/GitHub/Jobs/BuildZippy.psd1‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@{
2+
"runs-on" = "ubuntu-latest"
3+
if = '${{ success() }}'
4+
steps = @(
5+
@{
6+
name = 'Check out repository'
7+
uses = 'actions/checkout@main'
8+
}
9+
)
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@{
2+
name = 'PublishTestResults'
3+
uses = 'actions/upload-artifact@main'
4+
with = @{
5+
name = 'PesterResults'
6+
path = '**.TestResults.xml'
7+
}
8+
if = '${{always()}}'
9+
}
10+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#requires -Module PSDevOps
2+
param(
3+
$moduleName = $(
4+
$PSScriptRoot | Split-Path | Split-Path -Leaf
5+
)
6+
)
7+
8+
Import-BuildStep -SourcePath (
9+
Join-Path $PSScriptRoot 'GitHub'
10+
) -BuildSystem GitHubWorkflow
11+
12+
13+
Push-Location ($PSScriptRoot | Split-Path)
14+
New-GitHubWorkflow -Name "Build Module" -On Push,
15+
PullRequest,
16+
Demand -Job TestPowerShellOnLinux,
17+
TagReleaseAndPublish, "Build$moduleName" -OutputPath .\.github\workflows\build.yml
18+
19+
Pop-Location

‎CHANGELOG.md‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Zippy
2+
3+
## Zippy 0.1
4+
5+
* `Zippy` is a Quick Compression module (#1)
6+
* `Compress-Zippy` compresses content (#2)
7+
* `Expand-Zippy` expands content (#3)
8+
* `Zippy` builds, tests, and publishes with a workflow (#4)
9+
* `Zippy` tests (#5)
10+
* `Zippy` `README.md.ps1` (#6)
11+

‎Compress-Zippy.ps1‎

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
function Compress-Zippy {
2+
<#
3+
.SYNOPSIS
4+
Quickly Compresses Content
5+
.DESCRIPTION
6+
Compresses Content using a number of standard algorithms.
7+
8+
* Brotli (default)
9+
* Default
10+
* Gzip
11+
* Zlib
12+
.EXAMPLE
13+
Compress-Zippy "Hello World"
14+
.EXAMPLE
15+
Compress-Zippy "Hello World" -Algorithm Deflate
16+
.EXAMPLE
17+
Compress-Zippy "Hello World" -Algorithm GZip
18+
.EXAMPLE
19+
Compress-Zippy "Hello World" -Algorithm Zlib
20+
.EXAMPLE
21+
Compress-Zippy "Hello World" -Algorithm Brotli -AsByteStream
22+
.EXAMPLE
23+
Compress-Zippy "Hello World" -Algorithm Deflate -AsByteStream
24+
.EXAMPLE
25+
Compress-Zippy "Hello World" -Algorithm GZip -AsByteStream
26+
.EXAMPLE
27+
Compress-Zippy "Hello World" -Algorithm Zlib -AsByteStream
28+
#>
29+
param(
30+
# The text to compress
31+
[Parameter(ValueFromPipelineByPropertyName,ParameterSetName='Text',Position=0)]
32+
[Alias('String')]
33+
[string]
34+
$Text,
35+
36+
# A range of bytes to compress.
37+
[Parameter(ValueFromPipelineByPropertyName,ParameterSetName='Bytes')]
38+
[Alias('byte')]
39+
[byte[]]
40+
$Bytes,
41+
42+
# A stream to compress.
43+
[Parameter(ValueFromPipelineByPropertyName,ParameterSetName='Stream')]
44+
[Alias('streams')]
45+
[IO.Stream]
46+
$Stream,
47+
48+
# The compression algorithm.
49+
# By default, Brotli.
50+
[ValidateSet('Brotli','Deflate', 'GZip', 'ZLib')]
51+
[Alias('CompressionAlgorithm')]
52+
[string]
53+
$Algorithm = 'Brotli',
54+
55+
# The text encoding.
56+
# By default, this will be the `$outputEncoding`
57+
[Text.Encoding]
58+
$Encoding = $OutputEncoding,
59+
60+
# The compression level.
61+
# By default, this will be `fastest`.
62+
[IO.Compression.CompressionLevel]
63+
$CompressionLevel = 'Fastest',
64+
65+
# If set, will output a byte stream.
66+
# If not set, will output a base64 encoded string.
67+
[Alias('AsBytes','AsByte')]
68+
[switch]
69+
$AsByteStream
70+
)
71+
72+
73+
try {
74+
$compressor = "IO.Compression.${Algorithm}Stream" -as [type]
75+
76+
$outputStream = [IO.MemoryStream]::new()
77+
$compressedStream = $compressor::new($outputStream, $CompressionLevel)
78+
switch ($PSCmdlet.ParameterSetName) {
79+
Text {
80+
$Bytes = $Encoding.GetBytes($Text)
81+
$compressedStream.Write($Bytes,0,$Bytes.Length)
82+
}
83+
Bytes {
84+
$compressedStream.Write($Bytes,0,$Bytes.Length)
85+
}
86+
Stream {
87+
$Stream.CopyTo($compressedStream)
88+
}
89+
}
90+
$compressedStream.Close()
91+
$compressedStream.Dispose()
92+
93+
if ($AsByteStream) {
94+
$psCmdlet.WriteObject($outputStream.ToArray())
95+
}
96+
else {
97+
[Convert]::ToBase64String(
98+
$outputStream.ToArray()
99+
)
100+
}
101+
} catch {
102+
$PSCmdlet.WriteError($_)
103+
}
104+
finally {
105+
if ($outputStream) {
106+
$outputStream.Close()
107+
$outputStream.Dispose()
108+
}
109+
}
110+
}

‎Expand-Zippy.ps1‎

7.71 KB
Binary file not shown.

‎README.md‎

Lines changed: 152 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,153 @@
11
# Zippy
2-
Easy Compression in PowerShell
2+
[![Zippy](https://img.shields.io/powershellgallery/dt/Zippy)](https://www.powershellgallery.com/packages/Zippy/)
3+
## Easy Compression in PowerShell
4+
Zippy is a quick compression module.
5+
6+
* `Compress-Zippy` compresses content
7+
* `Expand-Zippy` expands contents
8+
9+
Zippy currently supports four compression algorithms:
10+
11+
* [Brotli](https://learn.microsoft.com/en-us/dotnet/api/system.io.compression.brotlistream?wt.mc_id=MVP_321542)
12+
* [Deflate](https://learn.microsoft.com/en-us/dotnet/api/system.io.compression.deflatestream?wt.mc_id=MVP_321542)
13+
* [GZip](https://learn.microsoft.com/en-us/dotnet/api/system.io.compression.gzipstream?wt.mc_id=MVP_321542)
14+
* [Zlib](https://learn.microsoft.com/en-us/dotnet/api/system.io.compression.zlibstream?wt.mc_id=MVP_321542)
15+
16+
17+
## Installing and Importing
18+
19+
You can install Zippy from the [PowerShell gallery](https://powershellgallery.com/)
20+
21+
~~~PowerShell
22+
Install-Module Zippy -Scope CurrentUser -Force
23+
~~~
24+
25+
Once installed, you can import the module with:
26+
27+
~~~PowerShell
28+
Import-Module Zippy -PassThru
29+
~~~
30+
31+
32+
You can also clone the repo and import the module locally:
33+
34+
~~~PowerShell
35+
git clone https://github.com/PoshWeb/Zippy
36+
cd ./Zippy
37+
Import-Module ./ -PassThru
38+
~~~
39+
40+
## Functions
41+
Zippy has 2 functions
42+
### Compress-Zippy
43+
#### Quickly Compresses Content
44+
Compresses Content using a number of standard algorithms.
45+
46+
* Brotli (default)
47+
* Default
48+
* Gzip
49+
* Zlib
50+
##### Parameters
51+
52+
|Name|Type|Description|
53+
|-|-|-|
54+
|Text|String|The text to compress|
55+
|Bytes|Byte[]|A range of bytes to compress.|
56+
|Stream|Stream|A stream to compress.|
57+
|Algorithm|String|The compression algorithm.<br/>By default, Brotli.|
58+
|Encoding|Encoding|The text encoding.<br/>By default, this will be the `$outputEncoding`|
59+
|CompressionLevel|CompressionLevel|The compression level.<br/>By default, this will be `fastest`.|
60+
|AsByteStream|SwitchParameter|If set, will output a byte stream.<br/>If not set, will output a base64 encoded string.|
61+
62+
##### Examples
63+
###### Example 1
64+
~~~PowerShell
65+
Compress-Zippy "Hello World"
66+
~~~
67+
###### Example 2
68+
~~~PowerShell
69+
Compress-Zippy "Hello World" -Algorithm Deflate
70+
~~~
71+
###### Example 3
72+
~~~PowerShell
73+
Compress-Zippy "Hello World" -Algorithm GZip
74+
~~~
75+
###### Example 4
76+
~~~PowerShell
77+
Compress-Zippy "Hello World" -Algorithm Zlib
78+
~~~
79+
###### Example 5
80+
~~~PowerShell
81+
Compress-Zippy "Hello World" -Algorithm Brotli -AsByteStream
82+
~~~
83+
###### Example 6
84+
~~~PowerShell
85+
Compress-Zippy "Hello World" -Algorithm Deflate -AsByteStream
86+
~~~
87+
###### Example 7
88+
~~~PowerShell
89+
Compress-Zippy "Hello World" -Algorithm GZip -AsByteStream
90+
~~~
91+
###### Example 8
92+
~~~PowerShell
93+
Compress-Zippy "Hello World" -Algorithm Zlib -AsByteStream
94+
~~~
95+
### Expand-Zippy
96+
#### Expands Compressed Data
97+
Expands Compressed Data using the .NET GZipStream class
98+
##### Parameters
99+
100+
|Name|Type|Description|
101+
|-|-|-|
102+
|CompressedData|String|The compressed data, as a Base64 string|
103+
|BinaryData|Byte[]|The compressed data, as a byte array|
104+
|AsByteStream|SwitchParameter|If set, will output a `byte[]` of decompressed bytes.|
105+
|AsBase64|SwitchParameter|If set, will output the decompressed data as a base64 string|
106+
|Algorithm|String|The compression algorithm.<br/>By default, Brotli.|
107+
|Encoding|Encoding|The text encoding.<br/>By default, this will be the $outputEncoding|
108+
109+
##### Examples
110+
###### Example 1
111+
~~~PowerShell
112+
Compress-Zippy -String ("abc" * 1kb) |
113+
Expand-Zippy
114+
~~~
115+
###### Example 2
116+
~~~PowerShell
117+
Compress-Zippy "Hello World" | Expand-Zippy
118+
~~~
119+
###### Example 3
120+
~~~PowerShell
121+
Compress-Zippy "Hello World" -Algorithm Deflate |
122+
Expand-Zippy -Algorithm Deflate
123+
~~~
124+
###### Example 4
125+
~~~PowerShell
126+
Compress-Zippy "Hello World" -Algorithm GZip |
127+
Expand-Zippy -Algorithm GZip
128+
~~~
129+
###### Example 5
130+
~~~PowerShell
131+
Compress-Zippy "Hello World" -Algorithm Zlib |
132+
Expand-Zippy -Algorithm Zlib
133+
~~~
134+
###### Example 6
135+
~~~PowerShell
136+
Compress-Zippy "Hello World" -Algorithm Brotli -AsByteStream |
137+
Expand-Zippy
138+
~~~
139+
###### Example 7
140+
~~~PowerShell
141+
Compress-Zippy "Hello World" -Algorithm Deflate -AsByteStream |
142+
Expand-Zippy -Algorithm Deflate
143+
~~~
144+
###### Example 8
145+
~~~PowerShell
146+
Compress-Zippy "Hello World" -Algorithm GZip -AsByteStream |
147+
Expand-Zippy -Algorithm GZip
148+
~~~
149+
###### Example 9
150+
~~~PowerShell
151+
Compress-Zippy "Hello World" -Algorithm Zlib -AsByteStream |
152+
Expand-Zippy -Algorithm Zlib
153+
~~~

0 commit comments

Comments
 (0)