based/src/Encoding/UnixToUnix.hs

31 lines
1016 B
Haskell

module Encoding.UnixToUnix
( encuu
, decuu
) where
import Data.ByteString as B
import qualified Data.ByteString.Char8 as BC
import qualified Codec.Binary.Uu as UU
import Data.ByteString.UTF8 as BSU -- from utf8-string
import qualified Data.Text as T
import qualified Data.Text.Encoding as T
import qualified Data.Text.IO as T
-- decuu :: String -> String
-- -- decuu = C.unpack . U.fromRight . UU.decode . BSU.fromString
-- decuu input =
-- case UU.decode (T.encodeUtf8 (T.pack input)) of
-- Right decoded -> T.unpack (T.decodeUtf8 decoded)
-- Left _ -> "Error decoding UU.\n"
decuu :: B.ByteString -> B.ByteString
decuu input = case UU.decode input of
Right byteString -> byteString
Left _ -> BC.pack "Error: Invalid Unix to Unix encoding input"
-- encuu :: String -> String
-- -- encuu = C.unpack . UU.encode . BSU.fromString
-- encuu = T.unpack . T.decodeUtf8 . UU.encode . T.encodeUtf8 . T.pack
encuu :: B.ByteString -> B.ByteString
encuu = UU.encode