Decompressing file with Zstd

I’m trying to decompress a zstd compressed file using the Elixir, and the library https://github.com/chenzhuoyu/elixir-zstd

I’ve tried the following

    {:ok, content} = File.read("myfile")
    <<header :: binary-size(12), remainder :: binary>> = content

    {:ok, orig} = ExZstd.simple_decompress(remainder)

->  ** (MatchError) no match of right hand side value: {:error, 'Unable to determain decompressed size'}

There er no problems when running the zstd command from the terminal.

I’ve also trying the streaming solution, found in the test example.

But i fail to see how i get the tail, when the data is from a file, and not a compression stream.

Any who can help me out, or should i simply resort to calling the zstd command directly from my code.

I don’t know this library, but I bet you need to pass the whole file contents in rather than discarding the header.

1 Like

That is a header that we manually put in, in the the (rust) program that actually produces the file. :slight_smile: It only works in the terminal, if i remove the header we wrap it in.

Well with that error it’s failing on line:

Are you sure it is an actual zstd file? Have you tried writing out the file and skipping the header to a file and using the zstd program at that point?

Ah, ok

Yes, i’ve have tried writing remainder to a file, and then decompress it with zstd -d myfile.zst no problem. Maybe it’s version mismatch.

1 Like

It’s possible, it doesn’t look like that library links a built in zstd library but rather just whatever is available on the system. Maybe try a little hoist program to confirm that, like python with ffi for a quick link and test or so?

1 Like