在Linux和Windows上压缩、编码和解码字符串的方法(gzip、base64)

18

我有一个编码字符串,它是在Linux机器上使用以下命令进行编码的:

cat <file-name> | gzip | base64 -w0

我可以使用下面的方法解码并串联字符串:

echo '<encoded-string> | base64 -di | zcat

在Windows机器上是否有解码相同字符串的方法。


4
这个问题的价值在于它提供了有用的Linux单行命令!感谢。 - Sam
1个回答

0

方法:

echo VERY_LARGE_STRING | gzip | base64 -w0

... 受到 Linux 设置的限制:

getconf ARG_MAX

使用了下面的代码,救了我的一天。非常感谢 Karthik1234。

cat <file-name> | gzip | base64 -w0

以下是我们在C#中解压缩Linux中压缩的消息的方法 注意:您可能需要删除最后一个字节。

static byte[] Decompress(byte[] gzip)
{
    // Create a GZIP stream with decompression mode.
    // ... Then create a buffer and write into while reading from the GZIP stream.
    using (GZipStream stream = new GZipStream(new MemoryStream(gzip),
    CompressionMode.Decompress))
    {
        const int size = 4096;
        byte[] buffer = new byte[size];
        using (MemoryStream memory = new MemoryStream())
        {
            int count = 0;
            do
            {
                count = stream.Read(buffer, 0, size);
                if (count > 0)
                {
                memory.Write(buffer, 0, count);
                }
            }
            while (count > 0);
            return memory.ToArray();
        }
    }
}

不确定C#中的解决方案如何回答这个问题?我猜作者正在寻找类似的命令行解决方案。 - jhilgeman

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接