LibZip 0.0.1 → 0.0.2
raw patch · 2 files changed
+47/−8 lines, 2 files
Files
- Codec/Archive/LibZip.chs +44/−6
- LibZip.cabal +3/−2
Codec/Archive/LibZip.chs view
@@ -6,11 +6,23 @@ -- | Partial Haskell bindings to @libzip@ library. -- These bindings provide read-only access to zip archives. -- Produced with @c2hs@ for @libzip@ ver. 0.9.+--+-- API is not stabilized yet, especially high-level part. If you use it, please+-- let me know. Feedback and suggestions are welcome. module Codec.Archive.LibZip (-- * Types Zip,ZipFile,OpenFlag(..),FileFlag(..),ZipError(..)- -- * High-level Haskell functions- ,withZip,getFiles,getFileSize,readZipFile+ ,Word8+ -- * High-level interface+ -- These functions are intended to reduce boiler-plate. They acquire and+ -- release relevant resources automatically (open and close archives, files).+ ,withZip,getFiles,getFileSize+ ,readZipFile,readZipFile',readZipFileHead,readZipFileHead'+ -- * Low-level direct bindings to @libzip@ functions+ -- These functions correspond to their C namesakes with @zip_@ prefix.+ -- Please refer to @libzip@ documentation to learn about their semantics.+ ,open,close,get_num_files,get_name+ ,fopen,fclose,fread -- * Utilities ,catchZipError,isFile,isDir ) where@@ -34,6 +46,7 @@ } deriving (Show,Eq) #} -- | Flags for 'getFiles', 'getFileSize', 'readZipFile', ...+-- Please consult @libzip@ documentation about their use. {# enum define FileFlag { ZIP_FL_NOCASE as FileNOCASE , ZIP_FL_NODIR as FileNODIR@@ -278,18 +291,42 @@ then E.throwIO ErrINTERNAL -- FIXME else fromIntegral <$> {# get zip_stat_t->size #} st --- | Read uncompressed file from the archive.+-- | Read uncompressed file from the archive. Produce a strict ByteString. readZipFile :: Zip -- ^ zip archive -> String -- ^ name of the file in the archive -> [FileFlag] -- ^ file name mode -> IO B.ByteString-readZipFile z fname flags = do+readZipFile z fname flags = return . B.pack =<< readZipFile' z fname flags++-- | Read uncompressed file from the archive. Produce a list of 'Word8'.+readZipFile' :: Zip -- ^ zip archive+ -> String -- ^ name of the file in the archive+ -> [FileFlag] -- ^ file name mode+ -> IO [Word8]+readZipFile' z fname flags = do sz <- getFileSize z fname flags+ readZipFileHead' z fname flags sz++-- | Read beginning of the uncompressed file from the archive. Produce a list of 'Word8'.+readZipFileHead' :: Zip -- ^ zip archive+ -> String -- ^ name of the file in the archive+ -> [FileFlag] -- ^ file name mode+ -> Int -- ^ how many bytes to read+ -> IO [Word8]+readZipFileHead' z fname flags n = do f <- fopen z fname flags- bytes <- fread f sz+ bytes <- fread f n fclose f- return $ B.pack bytes+ return bytes +-- | Read beginning of the uncompressed file from the archive. Produce a strict ByteString.+readZipFileHead :: Zip -- ^ zip archive+ -> String -- ^ name of the file in the archive+ -> [FileFlag] -- ^ file name mode+ -> Int -- ^ how many bytes to read+ -> IO B.ByteString+readZipFileHead z fname flags n = return . B.pack =<< readZipFileHead' z fname flags n+ -- Helpers -- | Wrapper to catch library errors.@@ -308,6 +345,7 @@ isDir :: String -> Bool isDir = not . isFile +lastMay :: [a] -> Maybe a lastMay [] = Nothing lastMay xs = Just $ last xs
LibZip.cabal view
@@ -1,5 +1,5 @@ Name: LibZip-Version: 0.0.1+Version: 0.0.2 License: BSD3 License-File: LICENSE Author: Sergey Astanin@@ -12,7 +12,8 @@ Description: This package provides basic read-only access to zip-archives. It is produced with @c2hs@ for @libzip@ ver. 0.9.-Exposed-modules: Codec.Archive.LibZip, C2HS+Exposed-modules: Codec.Archive.LibZip+Other-modules: C2HS Build-Type: Simple Cabal-Version: >= 1.2.3