I read that Char8 only supports ASCII characters and will be dangerous to use if you are using other Unicode characters
{-# LANGUAGE OverloadedStrings #-}
--import qualified Data.ByteString as B
import qualified Data.ByteString.Char8 as BC
import qualified Data.Text.IO as TIO
import qualified Data.Text.Encoding as E
import qualified Data.Text as T
name :: T.Text
name = "{ \"name\": \"哈时刻\" }"
nameB :: BC.ByteString
nameB = E.encodeUtf8 name
main :: IO ()
main = do
BC.writeFile "test.json" nameB
putStrLn "done"
produces the same result as
{-# LANGUAGE OverloadedStrings #-}
import qualified Data.ByteString as B
--import qualified Data.ByteString.Char8 as BC
import qualified Data.Text.IO as TIO
import qualified Data.Text.Encoding as E
import qualified Data.Text as T
name :: T.Text
name = "{ \"name\": \"哈时刻\" }"
nameB :: B.ByteString
nameB = E.encodeUtf8 name
main :: IO ()
main = do
B.writeFile "test.json" nameB
putStrLn "done"
So what is the difference of using Data.ByteString.Char8
vs Data.ByteString
BC.ByteString
is a re-export ofData.ByteString.ByteString
which you use asB.ByteString
- so these are literally referring to the same type and all the code is identical so... – Predominance