lib/encode.sh

490 B · 28 lines · bash

1#!/usr/bin/env bash
2
3brt_encode() {
4 local input="${1:-}"
5 if [[ -z "$input" ]]; then
6 brt_error "Usage: brt -encode <string|file>"
7 exit 1
8 fi
9 if [[ -f "$input" ]]; then
10 base64 < "$input"
11 else
12 printf '%s' "$input" | base64
13 fi
14}
15
16brt_decode() {
17 local input="${1:-}"
18 if [[ -z "$input" ]]; then
19 brt_error "Usage: brt -decode <string|file>"
20 exit 1
21 fi
22 if [[ -f "$input" ]]; then
23 base64 -d < "$input"
24 else
25 printf '%s' "$input" | base64 -d
26 fi
27}
28