Skip to content

return tuple for decompress #5

@Licenser

Description

@Licenser

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>>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions