1

当我用 LZ4 压缩/解压缩时,它给了我一些与原始字符串无关的东西。

例如“1234”是好的,但不能用一个句子。

这是更正的代码,感谢您的回答

   int Compress(const char* source, char* dest, int sourceSize, int maxDestSize)
    {
        return LZ4_compress_default(source, dest, sourceSize, maxDestSize);
    }

    int Decompress(const char* source, char* dest, int compressedSize, int maxDecompressedSize)
    {
        return LZ4_decompress_safe(source, dest, compressedSize, maxDecompressedSize);
    }

    int main()
    {
        char source[1024] = "Arguing that you don\'t care about the right to privacy because you have nothing to hide is no different than saying you don\'t care about free speech because you have nothing to say.";

        char buff[1024 * 4] = { 0 };
        char buff_a[1024 * 4] = { 0 };

        int x = Compress(source, buff, strlen(source), sizeof(buff));
        printf("\nBYTE COMPRESSED : %i\nDATA COMPRESSED : \n", x);
        for (int i = 0; i < x; i++)
            printf(" %2x", (unsigned)buff[i]);

        int y = Decompress(buff, buff_a, x, sizeof(buff_a));
        printf("\n\nBYTE DECOMPRESSED : %i\nDATA DECOMPRESSED : \n", y);
        for (int i = 0; i < y; i++)
            printf(" %02x", (unsigned)buff_a[i]);

        printf("\n\n\n\nEXIT\n");
        getchar();
        return 0;
    }
4

0 回答 0