libmagic 1.2 → 1.3
raw patch · 5 files changed
+26/−17 lines, 5 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
- Magic.Operations: magicCString :: Magic -> CStringLen -> IO String
+ Magic.Operations: magicCString :: Magic -> CStringLen -> IO ByteString
- Magic.Operations: magicFile :: Magic -> OsPath -> IO String
+ Magic.Operations: magicFile :: Magic -> OsPath -> IO ByteString
- Magic.Operations: magicStdin :: Magic -> IO String
+ Magic.Operations: magicStdin :: Magic -> IO ByteString
- Magic.Operations: magicString :: Magic -> String -> IO String
+ Magic.Operations: magicString :: Magic -> String -> IO ByteString
Files
- CHANGELOG +8/−0
- Magic/Init.hsc +4/−4
- Magic/Operations.hsc +12/−11
- Magic/TypesLL.hsc +1/−1
- libmagic.cabal +1/−1
CHANGELOG view
@@ -1,3 +1,11 @@+haskell-libmagic (1.3) unstable; urgency=medium++ * Use ByteString for magic results, rather than String+ * Small improvements to documentation.+ * Improved use of Coercion++ -- Joey Hess <id@joeyh.name> Mon, 26 Oct 2026 12:06:27 -0400+ haskell-libmagic (1.2) unstable; urgency=medium * Initial release, forked from John Goerzen's magic package.
Magic/Init.hsc view
@@ -15,7 +15,7 @@ Stability : provisional Portability: portable -Initialization and shutdown for magic programs+Initialization for magic programs Written by John Goerzen, jgoerzen\@complete.org -}@@ -34,7 +34,7 @@ import qualified Data.List.NonEmpty as NE import System.OsPath.Types import System.OsString.Internal.Types-import Data.Coerce+import Data.Type.Coercion import qualified Data.ByteString.Short as SBS {- | Create a Magic object. You must call either 'magicLoadDefault'@@ -59,8 +59,8 @@ s = SBS.intercalate ":" (map conv (NE.toList l)) conv p = case coercionToPlatformTypes of- Right _ -> getWindowsString (coerce p)- Left _ -> getPosixString (coerce p)+ Left (_, co) -> getWindowsString (coerceWith co p)+ Right (_, co) -> getPosixString (coerceWith co p) foreign import ccall unsafe "magic.h magic_open" magic_open :: CInt -> IO (Ptr CMagic)
Magic/Operations.hsc view
@@ -15,7 +15,7 @@ Stability : provisional Portability: portable -Initialization and shutdown for magic programs+Operations for magic programs Written by John Goerzen, jgoerzen\@complete.org -}@@ -36,40 +36,41 @@ import Magic.TypesLL import System.OsPath.Types import System.OsString.Internal.Types-import Data.Coerce+import Data.Type.Coercion+import qualified Data.ByteString as BS import qualified Data.ByteString.Short as SBS {- | Calls the Magic system on the specified file. -}-magicFile :: Magic -> OsPath -> IO String+magicFile :: Magic -> OsPath -> IO BS.ByteString magicFile magic fp = withMagicPtr magic $ \cmagic -> SBS.useAsCString sbsfp $ \cfp -> do res <- throwErrorIfNull "magicFile" cmagic (magic_file cmagic cfp)- peekCString res+ BS.packCString res where sbsfp = case coercionToPlatformTypes of- Right _ -> getWindowsString (coerce fp)- Left _ -> getPosixString (coerce fp)+ Left (_, co) -> getWindowsString (coerceWith co fp)+ Right (_, co) -> getPosixString (coerceWith co fp) {- | Calls the Magic system on stdin. -}-magicStdin :: Magic -> IO String+magicStdin :: Magic -> IO BS.ByteString magicStdin magic = withMagicPtr magic $ \cmagic -> do res <- throwErrorIfNull "magicStdin" cmagic (magic_file cmagic nullPtr)- peekCString res+ BS.packCString res {- | Calls the Magic system to process the given String. Please note: it is not evaluated lazily. -}-magicString :: Magic -> String -> IO String+magicString :: Magic -> String -> IO BS.ByteString magicString m s = withCStringLen s (magicCString m) {- | Lower-level function used to call the Magic system to process a C string. -}-magicCString :: Magic -> CStringLen -> IO String+magicCString :: Magic -> CStringLen -> IO BS.ByteString magicCString magic (cstr, len) = withMagicPtr magic $ \cmagic -> do res <- throwErrorIfNull "magicCString" cmagic (magic_buffer cmagic cstr (fromIntegral len))- peekCString res+ BS.packCString res {- | Change the flags on an already-created object. -} magicSetFlags :: Magic -> [MagicFlag] -> IO ()
Magic/TypesLL.hsc view
@@ -32,7 +32,7 @@ {- | Main Magic handle. -Magic objects are automatically closed (and memory freed) when they are+Magic handles are automatically closed (and memory freed) when they are garbage-collected by Haskell. There is no need to explicitly close them. Access to the C library is serialized, so multiple threads may safely
libmagic.cabal view
@@ -1,5 +1,5 @@ Name: libmagic-Version: 1.2+Version: 1.3 Cabal-Version: >= 1.10 License: BSD3 Maintainer: Joey Hess <id@joeyh.name>