2024-05-19 13:23:39 +02:00
|
|
|
module Encoding.Yenc
|
|
|
|
( ency
|
|
|
|
, decy
|
|
|
|
) where
|
|
|
|
|
|
|
|
|
2024-06-07 18:09:20 +02:00
|
|
|
import Data.ByteString as B
|
|
|
|
import qualified Data.ByteString.Char8 as BC
|
2024-05-19 13:23:39 +02:00
|
|
|
import Data.ByteString.UTF8 as BSU -- from utf8-string
|
|
|
|
import qualified Codec.Binary.Yenc as Y
|
|
|
|
|
2024-05-20 23:28:14 +02:00
|
|
|
import qualified Data.Text as T
|
|
|
|
import qualified Data.Text.Encoding as T
|
|
|
|
import qualified Data.Text.IO as T
|
|
|
|
|
2024-06-07 18:09:20 +02:00
|
|
|
-- 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"
|
2024-05-19 13:23:39 +02:00
|
|
|
|
2024-06-07 18:09:20 +02:00
|
|
|
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
|