@@ -1,53 +0,0 @@
1−{-# LANGUAGE DeriveDataTypeable #-}
2−{-# LANGUAGE DeriveGeneric #-}
3−{-# LANGUAGE GeneralizedNewtypeDeriving #-}
4−
5−-- |
6−-- Module : Network.Google.Data.Base64
7−-- Copyright : (c) 2013-2016 Brendan Hay
8−-- License : Mozilla Public License, v. 2.0.
9−-- Maintainer : Brendan Hay <brendan.g.hay@gmail.com>
10−-- Stability : provisional
11−-- Portability : non-portable (GHC extensions)
12−--
13−module Network.Google.Data.Base64
14− ( Base64 (..)
15− , _Base64
16− ) where
17−
18−import Control.Lens (Iso', iso)
19−import Data.Aeson (FromJSON (..), ToJSON (..))
20−import qualified Data.ByteArray.Encoding as BA
21−import Data.ByteString (ByteString)
22−import qualified Data.ByteString.Char8 as BS8
23−import Data.Data (Data, Typeable)
24−import Data.Hashable
25−import qualified Data.Text.Encoding as Text
26−import GHC.Generics (Generic)
27−import Network.Google.Data.JSON (parseJSONText, toJSONText)
28−import Web.HttpApiData (FromHttpApiData (..),
29− ToHttpApiData (..))
30−
31−-- | Base64 encoded binary data.
32−--
33−-- Encoding\/decoding is automatically deferred to serialisation and deserialisation
34−-- respectively.
35−newtype Base64 = Base64 { unBase64 :: ByteString }
36− deriving (Eq, Read, Ord, Data, Typeable, Generic)
37−
38−instance Hashable Base64
39−
40−_Base64 :: Iso' Base64 ByteString
41−_Base64 = iso unBase64 Base64
42−
43−instance ToHttpApiData Base64 where
44− toQueryParam = Text.decodeUtf8 . toHeader
45− toHeader = BA.convertToBase BA.Base64 . unBase64
46−
47−instance FromHttpApiData Base64 where
48− parseQueryParam = parseHeader . Text.encodeUtf8
49− parseHeader = either fail (pure . Base64) . BA.convertFromBase BA.Base64
50−
51−instance Show Base64 where show = show . BS8.unpack . unBase64
52−instance FromJSON Base64 where parseJSON = parseJSONText "Base64"
53−instance ToJSON Base64 where toJSON = toJSONText