module Data.Binary.Zlib where

import Codec.Compression.Zlib
import Data.Binary

newtype ZlibWrapper a = ZlibWrapper {ZlibWrapper a -> a
unZlibWrapper :: a}

instance Binary a => Binary (ZlibWrapper a) where
  put :: ZlibWrapper a -> Put
put = ByteString -> Put
forall t. Binary t => t -> Put
put (ByteString -> Put)
-> (ZlibWrapper a -> ByteString) -> ZlibWrapper a -> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> ByteString
compress (ByteString -> ByteString)
-> (ZlibWrapper a -> ByteString) -> ZlibWrapper a -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> ByteString
forall a. Binary a => a -> ByteString
encode (a -> ByteString)
-> (ZlibWrapper a -> a) -> ZlibWrapper a -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ZlibWrapper a -> a
forall a. ZlibWrapper a -> a
unZlibWrapper
  get :: Get (ZlibWrapper a)
get = a -> ZlibWrapper a
forall a. a -> ZlibWrapper a
ZlibWrapper (a -> ZlibWrapper a)
-> (ByteString -> a) -> ByteString -> ZlibWrapper a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> a
forall a. Binary a => ByteString -> a
decode (ByteString -> a) -> (ByteString -> ByteString) -> ByteString -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> ByteString
decompress (ByteString -> ZlibWrapper a)
-> Get ByteString -> Get (ZlibWrapper a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get ByteString
forall t. Binary t => Get t
get