haskell-zlib

Handling Haskell zlib decompression errors

╄→гoц情女王★ 提交于 2019-12-24 07:39:39
问题 I have a String x which may or may not be gzip-compressed. Using the zlib library, I want to try decompressing x -- if it succeeds, the function shall return the compressed String. If not (i.e. x is not gzip-compressed) I want to simply return x . As GZip.decompress generates an error if applied to a non-gzip string, I could use catch or similar, but I'm specifically asking for a solution that uses the zlib error handling mechanism. How can I write a function, say decompressIfPossible ::