I wish to produce a gzip'ed STRING in bash, and then send it to a php script for decoding/inflating. But I am coming across a problem with, I think, the gzip'ed string produced by gzip in bash.
# from
# https://stackoverflow.com/questions/7538846/un-decompress-a-string-in-bash#7539075
FOO="$(echo "Hello world" | gzip -c | base64)" # compressed, base64 encoded data
echo $FOO | base64 -d | gunzip # use base64 decoded, uncompressed data
echo '--'
# unpack base64 again before sending to php
FOO="$(echo $FOO | base64 -d)"
# this is where it goes wrong:
# php doesn't seem to like the gzip string format.
# gzuncompress produces:
# PHP Warning: gzuncompress(): data error in Command line code on line 1
php -r "echo gzuncompress('$FOO') . \"\n\";"
echo '--'
# gzdecode produces:
# PHP Warning: gzdecode(): data error in Command line code on line 1
php -r "echo gzdecode('$FOO') . \"\n\";"
echo '--'
# gzinflate produces:
# PHP Warning: gzinflate(): data error in Command line code on line 1
php -r "echo gzinflate('$FOO') . \"\n\";"
echo '--'
I am suspecting that the problem may be with the bash gzip format.
But I am unable to see any options that might correct this.
All thoughts appreciated.