more OsPath conversion (639/749)

Sponsored-by: k0ld
This commit is contained in:
Joey Hess 2025-02-07 16:07:05 -04:00
parent a5d48edd94
commit c74c75b352
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
28 changed files with 147 additions and 132 deletions

View file

@ -8,6 +8,7 @@
-}
{-# LANGUAGE FlexibleInstances, TypeSynonymInstances #-}
{-# LANGUAGE CPP #-}
module Utility.Aeson (
module X,
@ -32,6 +33,9 @@ import qualified Data.Vector
import Prelude
import Utility.FileSystemEncoding
#ifdef WITH_OSPATH
import Utility.OsPath
#endif
-- | Use this instead of Data.Aeson.encode to make sure that the
-- below String instance is used.
@ -60,6 +64,11 @@ instance ToJSON' String where
instance ToJSON' S.ByteString where
toJSON' = toJSON . packByteString
#ifdef WITH_OSPATH
instance ToJSON' OsPath where
toJSON' p = toJSON' (fromOsPath p :: S.ByteString)
#endif
-- | Pack a String to Text, correctly handling the filesystem encoding.
--
-- Use this instead of Data.Text.pack.

View file

@ -14,7 +14,6 @@ module Utility.HtmlDetect (
import Author
import qualified Utility.FileIO as F
import Utility.RawFilePath
import Utility.OsPath
import Text.HTML.TagSoup
@ -60,8 +59,8 @@ isHtmlBs = isHtml . B8.unpack
-- It would be equivalent to use isHtml <$> readFile file,
-- but since that would not read all of the file, the handle
-- would remain open until it got garbage collected sometime later.
isHtmlFile :: RawFilePath -> IO Bool
isHtmlFile file = F.withFile (toOsPath file) ReadMode $ \h ->
isHtmlFile :: OsPath -> IO Bool
isHtmlFile file = F.withFile file ReadMode $ \h ->
isHtmlBs <$> B.hGet h htmlPrefixLength
-- | How much of the beginning of a html document is needed to detect it.