based/src/Encoding/Yenc.hs

32 lines
907 B
Haskell

module Encoding.Yenc
( ency
, decy
) where
import Data.ByteString as B
import qualified Data.ByteString.Char8 as BC
import Data.ByteString.UTF8 as BSU -- from utf8-string
import qualified Codec.Binary.Yenc as Y
import qualified Data.Text as T
import qualified Data.Text.Encoding as T
import qualified Data.Text.IO as T
-- decy :: String -> String
-- -- decy = C.unpack . U.fromRight . Y.decode . BSU.fromString
-- decy input =
-- case Y.decode (BSU.fromString input) of
-- Right decoded -> T.unpack (T.decodeUtf8 decoded)
-- Left _ -> "Error decoding Y.\n"
decy :: B.ByteString -> B.ByteString
decy input = case Y.decode input of
Right byteString -> byteString
Left _ -> BC.pack "Error: Invalid YEncoding input"
-- ency :: String -> String
-- ency = C.unpack . Y.encode . BSU.fromString
ency :: B.ByteString -> B.ByteString
ency = Y.encode