fdmanana/snappy-erlang-nif — pull request #10 by pmembrey (2014-05-16 14:36:49+00:00)
Title: Snappy should be able to decompress an empty binary

Hi guys,

A year ago I raised an issue (https://github.com/fdmanana/snappy-erlang-nif/issues/6) discussing the case where the Snappy library will accept an empty binary and return:

```
{ok, <<>>}
```

but if you try to decompress an empty binary, it will throw an error. This is a big problem if you're writing data to disk and running everything through Snappy because you expect that everything you read back will be decompressable.

Admittedly it can be argued whether or not an empty binary *is* valid for compression. I'd say it probably isn't but given that people might already be using it with this behaviour, I wanted a backwards compatible change.

This change will return an empty binary:

```
{ok, <<>>} = snappy:decompress(<<>>).
```

Whilst I was at it, I added some code to short cut the compression cycle if compression is attempt on an empty binary. The same value is returned, just it doesn't go through the compression engine itself.

I'm happy to cancel this pull request and add code to make attempting to compress an empty binary an error condition.

Cheers,

Pete