ref: 8d327931447ae27016b96ab5e68c9cd682ba92a1
parent: 0d58eccf953017135910c4ab7a1666c50a5e2265
author: Lennart Augustsson <lennart.augustsson@epicgames.com>
date: Thu Feb 22 14:40:16 EST 2024
Add Compress
--- a/MicroHs.cabal
+++ b/MicroHs.cabal
@@ -76,6 +76,7 @@
Compat
PrimTable
System.IO.MD5
+ System.Compress
Paths_MicroHs
autogen-modules: Paths_MicroHs
build-depends: base >= 4.10 && < 4.20,
--- /dev/null
+++ b/ghc/System/Compress.hs
@@ -1,0 +1,4 @@
+module System.Compress(compress) where
+
+compress :: String -> String
+compress _ = error "compress: not available with ghc"
--- /dev/null
+++ b/lib/System/Compress.hs
@@ -1,0 +1,21 @@
+module System.Compress(compress) where
+import Foreign.C.String
+import Foreign.Marshal.Alloc
+import Foreign.Marshal.Utils
+import Foreign.Ptr
+import Foreign.Storable
+import System.IO.Unsafe
+
+foreign import ccall "lz77c" c_lz77c :: CString -> Int -> Ptr CString -> IO Int
+
+-- This really ought to be [Word8] -> [Word8]
+compress :: String -> String
+compress file = unsafePerformIO $ do
+ (iptr, ilen) <- newCAStringLen file
+ pptr <- new nullPtr
+ olen <- c_lz77c iptr ilen pptr
+ optr <- peek pptr
+ res <- peekCAStringLen (optr, olen)
+ free iptr
+ free optr
+ return res
--
⑨