module Network.AWS.Data.Internal.Base64
( Base64
) where
import Data.Aeson.Types
import qualified Data.Attoparsec.Text as AText
import Data.ByteString (ByteString)
import qualified Data.ByteString.Base64 as Base64
import qualified Data.Text.Encoding as Text
import GHC.Generics
import Network.AWS.Data.Internal.ByteString
import Network.AWS.Data.Internal.JSON
import Network.AWS.Data.Internal.Query
import Network.AWS.Data.Internal.Text
import Network.AWS.Data.Internal.XML
newtype Base64 = Base64 { unBase64 :: ByteString }
deriving (Eq, Ord, Generic)
instance FromText Base64 where
parser = AText.takeText >>=
either fail (return . Base64) . Base64.decode . Text.encodeUtf8
instance Show Base64 where show = show . toBS
instance ToText Base64 where toText = Text.decodeUtf8 . toBS
instance ToByteString Base64 where toBS = Base64.encode . unBase64
instance ToQuery Base64 where toQuery = toQuery . toText
instance FromXML Base64 where parseXML = parseXMLText "Base64"
instance ToXML Base64 where toXML = toXMLText
instance FromJSON Base64 where parseJSON = parseJSONText "Base64"
instance ToJSON Base64 where toJSON = toJSONText