feat(encode64): add encodefile64 function (#10813)

Co-authored-by: Jeremy Combs <jeremy.combs@convergetp.com>
This commit is contained in:
Jeremy Combs 2022-11-06 14:50:39 -05:00 committed by GitHub
parent 80fdbc9b91
commit 3eda3e5650
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 4 deletions

View file

@ -11,8 +11,9 @@ plugins=(... encode64)
## Functions and Aliases
| Function | Alias | Description |
| ---------- | ----- | ------------------------------ |
| -------------- | ------ | -------------------------------------- |
| `encode64` | `e64` | Encodes given data to base64 |
| `encodefile64` | `ef64` | Encodes given file's content to base64 |
| `decode64` | `d64` | Decodes given data from base64 |
## Usage and examples
@ -37,6 +38,20 @@ plugins=(... encode64)
b2gtbXktenNo==
```
### Encoding a file
Encode a file's contents to base64 and save output to text file.
**NOTE:** Takes provided file and saves encoded content as new file with `.txt` extension
- From parameter
```console
$ encodefile64 ohmyzsh.icn
ohmyzsh.icn's content encoded in base64 and saved as ohmyzsh.icn.txt
$ ef64 "oh-my-zsh"
ohmyzsh.icn's content encoded in base64 and saved as ohmyzsh.icn.txt
```
### Decoding
- From parameter

View file

@ -6,6 +6,15 @@ encode64() {
fi
}
encodefile64() {
if [[ $# -eq 0 ]]; then
echo "You must provide a filename"
else
base64 -i $1 -o $1.txt
echo "${1}'s content encoded in base64 and saved as ${1}.txt"
fi
}
decode64() {
if [[ $# -eq 0 ]]; then
cat | base64 --decode
@ -14,4 +23,5 @@ decode64() {
fi
}
alias e64=encode64
alias ef64=encodefile64
alias d64=decode64