(Un/De)compress a string in bash?

前端 未结 2 1118
独厮守ぢ
独厮守ぢ 2021-02-20 12:41

Is it possible to compress/decompress a string in bash using stdin/stdout ?

I tried this but apparently it is not supported ?



        
2条回答
  •  春和景丽
    2021-02-20 13:16

    If 33% compression rate loss is acceptable for you, then you can store base64 encoded compressed data:

    me$mybox$ FOO=$(echo "Hello world" | gzip | base64 -w0) # compressed, base64 encoded data
    me$mybox$ echo $FOO | base64 -d | gunzip # use base64 decoded, uncompressed data
    Hello world
    

    It will work, but each 3 (compressed) bytes will be stored in 4 bytes of text.

提交回复
热议问题