Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

return tuple for decompress #5

Open
Licenser opened this issue Mar 30, 2018 · 0 comments
Open

return tuple for decompress #5

Licenser opened this issue Mar 30, 2018 · 0 comments

Comments

@Licenser
Copy link
Contributor

This is slightly related to #4 but goes further so I wanted to ticket it.

I would like to open a PR to change the return of decompress to error | {ok, Uncompressed}. The reason for that is that it will allow clearer matching and guarding against wrong returns.

Right now using a code like:

Uncompressed = zstd:decompress(In),
<<Acc/binary, Uncompressed/binary>>

can lead to odd errors in places where the error doesn't occur when the In value isn't a valid compressed binary.

It would require additional matching to guard against handing on invalid data For example:

Uncompressed = case zstd:decompress(In) of
  X when is_binary(X) ->  X
end,
<<Acc/binary, Uncompressed/binary>>

returning a tuple would allow to guard against handing on bad data right during decoding time and failing fast:

{ok, Uncompressed} = zstd:decompress(In),
<<Acc/binary, Uncompressed/binary>>
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant