commit 007e8a6260b037a3b392ca1d2515805a8c5ae812
parent 1b38ee123a1d506816d80362a1153b6b136ec07d
Author: Jan Pobrislo <ccx@webprojekty.cz>
Date: Fri, 27 Nov 2015 19:19:20 +0100
use base64 for encoding binary files
Diffstat:
2 files changed, 32 insertions(+), 13 deletions(-)
diff --git a/bin/fileset.awk b/bin/fileset.awk
@@ -169,6 +169,16 @@ function process_statement() {
continue
}
+ # binary, base64; decodes the arguments and changes file content
+ if(cchar ~ /[bB]/) {
+ shellfunc("f 1", crest)
+ content = get_argument(cchar == "B")
+
+ base64_redir = (crest ~ /a/ ? ">>" : ">") fname
+ print_d("base64 "base64_redir" <<<"quoted(content))
+ continue
+ }
+
# run shell command
if(cchar == "!") {
# use as Filter
diff --git a/bin/fslist b/bin/fslist
@@ -39,6 +39,11 @@ ROOT=${${${ROOT:-$PWD}:A}%/}
: ${print_m:=1}
: ${print_o:=1}
: ${print_c:=1}
+if (($+commands[file])) && (($+commands[base64])); then
+ : ${print_b:=1}
+else
+ : ${print_b:=0}
+fi
fnames=( )
for arg in "${@:-$ROOT}"; do
@@ -85,21 +90,25 @@ for fname in $fnames; do
statement $'l\t'$s[link] $'\t'
elif [[ $t == f ]]; then
if (($print_c)); then
- IFS= read -r -d '' content <$fname
- flags=''
- if [[ $content == *$'\n' ]]; then
- content=${content%$'\n'}
+ if (($print_b)) && [[ $(file -bi $fname) != text/* ]]; then
+ statement B$'\t'"$(base64 <$fname)" $'\n'
+ else
+ IFS= read -r -d '' content <$fname
+ flags=''
if [[ $content == *$'\n' ]]; then
- # force appending newline
- flags+=n
+ content=${content%$'\n'}
+ if [[ $content == *$'\n' ]]; then
+ # force appending newline
+ flags+=n
+ fi
+ else
+ flags+=N
+ fi
+ if ! (($compact)) || [[ $content == *$'\t'* || $content == *$'\n'* ]]; then
+ statement C$flags$'\t'$content $'\n'
+ else
+ statement c$flags$'\t'$content
fi
- else
- flags+=N
- fi
- if ! (($compact)) || [[ $content == *$'\t'* || $content == *$'\n'* ]]; then
- statement C$flags$'\t'$content $'\n'
- else
- statement c$flags$'\t'$content
fi
else
statement f