packages feed

ztar 0.1.2 → 0.1.3

raw patch · 11 files changed

+136/−33 lines, 11 filesdep ~path

Dependency ranges changed: path

Files

CHANGELOG.md view
@@ -1,3 +1,8 @@+# ztar 0.1.3++Changes:+* Add the `typed-paths` flag for using the `Path` library+ # ztar 0.1.2  Changes:
README.md view
@@ -26,3 +26,24 @@ extract "archive-gz/" "archive.tar.gz" extract "archive-zip/" "archive.zip" ```++## Using the Path library++If your code uses the [`Path`](https://hackage.haskell.org/package/path) library for more+type-safe filepaths, include the `typed-paths` flag.++```+# stack.yaml+flags:+  ztar:+    typed-paths: true++# Main.hs+import Path+import Path.IO++home <- getHomeDir+let archive = home </> [relfile|archive.tgz|]+dir <- resolveDir "dist/"+create GZip archive dir+```
src/Codec/Archive/ZTar.hs view
@@ -21,6 +21,7 @@ import qualified Data.ByteString.Lazy as BS  import qualified Codec.Archive.ZTar.GZip as GZip+import Codec.Archive.ZTar.Path import qualified Codec.Archive.ZTar.Tar as Tar import qualified Codec.Archive.ZTar.Zip as Zip @@ -33,15 +34,15 @@  -- | Create a new archive from the given directory using the given compression algorithm. create :: Compression-       -> FilePath -- ^ archive file to create-       -> FilePath -- ^ directory to archive+       -> PathFile b0 -- ^ archive file to create+       -> PathDir b1 -- ^ directory to archive        -> IO () create compression archive dir = create' compression archive dir ["."]  -- | Create a new archive from the given paths using the given compression algorithm. create' :: Compression-        -> FilePath -- ^ archive file to create-        -> FilePath -- ^ base directory+        -> PathFile b0 -- ^ archive file to create+        -> PathDir b1 -- ^ base directory         -> [FilePath] -- ^ files and paths to compress, relative to base directory         -> IO () create' compression = case compression of@@ -51,11 +52,11 @@  -- | Extract an archive to the given directory. Automatically detects the compression algorithm. -- used in the archive.-extract :: FilePath -- ^ destination directory-        -> FilePath -- ^ archive to extract+extract :: PathDir b0 -- ^ destination directory+        -> PathFile b1 -- ^ archive to extract         -> IO ()-extract dir archive = BS.readFile archive >>= \case+extract dir archive = BS.readFile (toFP archive) >>= \case   Tar.TarFormat -> Tar.extract dir archive   GZip.GZipFormat -> GZip.extract dir archive   Zip.ZipFormat -> Zip.extract dir archive-  _ -> fail $ "Could not recognize archive format: " ++ archive+  _ -> fail $ "Could not recognize archive format: " ++ (toFP archive)
src/Codec/Archive/ZTar/GZip.hs view
@@ -21,6 +21,8 @@ import Data.ByteString.Lazy (ByteString) import qualified Data.ByteString.Lazy as BS +import Codec.Archive.ZTar.Path+ -- | A pattern matching any ByteString in the GZip format. pattern GZipFormat :: ByteString pattern GZipFormat <- ((BS.pack [0x1F, 0x8B] `BS.isPrefixOf`) -> True)@@ -30,18 +32,20 @@ -- It is equivalent to calling the standard 'tar' program like so: -- -- @$ tar -czf archive -C base paths@-create :: FilePath -- ^ archive to create-       -> FilePath -- ^ base directory+create :: PathFile b0 -- ^ archive to create+       -> PathDir b1 -- ^ base directory        -> [FilePath] -- ^ files and paths to compress, relative to base directory        -> IO ()-create archive base paths = BS.writeFile archive . GZ.compress . Tar.write =<< Tar.pack base paths+create (toFP -> archive) (toFP -> base) paths =+  BS.writeFile archive . GZ.compress . Tar.write =<< Tar.pack base paths  -- | Extract all the files contained in an archive compressed with GZip. -- -- It is equivalent to calling the standard 'tar' program like so: -- -- @$ tar -xf archive -C dir@-extract :: FilePath -- ^ destination directory-        -> FilePath -- ^ archive to extract+extract :: PathDir b0 -- ^ destination directory+        -> PathFile b1 -- ^ archive to extract         -> IO ()-extract dir archive = Tar.unpack dir . Tar.read . GZ.decompress =<< BS.readFile archive+extract (toFP -> dir) (toFP -> archive) =+  Tar.unpack dir . Tar.read . GZ.decompress =<< BS.readFile archive
+ src/Codec/Archive/ZTar/Path.hs view
@@ -0,0 +1,37 @@+{-|+Module      :  Codec.Archive.ZTar.Path+Maintainer  :  Brandon Chinn <brandonchinn178@gmail.com>+Stability   :  experimental+Portability :  portable++Types for representing filepaths.+-}+{-# LANGUAGE CPP #-}++module Codec.Archive.ZTar.Path+  ( PathFile+  , PathDir+  , toFP+  ) where++#ifdef TYPED_PATHS++import Path++type PathFile b = Path b File+type PathDir b = Path b Dir++-- | Convert a Path into a FilePath.+toFP :: Path b t -> FilePath+toFP = toFilePath++#else++type PathFile b = FilePath+type PathDir b = FilePath++-- | Convert a FilePath into a FilePath.+toFP :: FilePath -> FilePath+toFP = id++#endif
src/Codec/Archive/ZTar/Tar.hs view
@@ -17,10 +17,11 @@   , extract   ) where +import qualified Codec.Archive.Tar as Tar import Data.ByteString.Lazy (ByteString) import qualified Data.ByteString.Lazy as BS -import qualified Codec.Archive.Tar as Tar+import Codec.Archive.ZTar.Path  -- | A pattern matching any ByteString in an uncompressed TAR format. pattern TarFormat :: ByteString@@ -39,18 +40,18 @@ -- It is equivalent to calling the standard 'tar' program like so: -- -- @$ tar -cf archive -C base paths@-create :: FilePath -- ^ archive to create-       -> FilePath -- ^ base directory+create :: PathFile b0 -- ^ archive to create+       -> PathDir b1 -- ^ base directory        -> [FilePath] -- ^ files and paths to compress, relative to base directory        -> IO ()-create = Tar.create+create (toFP -> archive) (toFP -> base) paths = Tar.create archive base paths  -- | Extract all the files contained in an uncompressed tar archive. -- -- It is equivalent to calling the standard 'tar' program like so: -- -- @$ tar -xf archive -C dir@-extract :: FilePath -- ^ destination directory-        -> FilePath -- ^ archive to extract+extract :: PathDir b0 -- ^ destination directory+        -> PathFile b1 -- ^ archive to extract         -> IO ()-extract = Tar.extract+extract (toFP -> dir) (toFP -> archive) = Tar.extract dir archive
src/Codec/Archive/ZTar/Zip.hs view
@@ -32,6 +32,8 @@     ) import System.FilePath ((</>)) +import Codec.Archive.ZTar.Path+ -- | A pattern matching any ByteString in the Zip format. pattern ZipFormat :: ByteString pattern ZipFormat <- ((BS.pack [0x50, 0x4B, 0x03, 0x04] `BS.isPrefixOf`) -> True)@@ -41,11 +43,11 @@ -- It is equivalent to calling the standard 'zip' program like so: -- -- @$ CURR=$PWD; (cd base && zip -r archive paths && mv archive $CURR)@-create :: FilePath -- ^ archive to create-       -> FilePath -- ^ base directory+create :: PathFile b0 -- ^ archive to create+       -> PathDir b1 -- ^ base directory        -> [FilePath] -- ^ files and paths to compress, relative to base directory        -> IO ()-create archive base paths = do+create (toFP -> archive) (toFP -> base) paths = do   archive' <- makeAbsolute archive >>= parseAbsFile   withCurrentDirectory base $ Zip.createArchive archive' $ mapM_ insert paths   where@@ -69,10 +71,10 @@ -- It is equivalent to calling the standard 'zip' program like so: -- -- @$ mkdir -p dir && unzip archive -d dir@-extract :: FilePath -- ^ destination directory-        -> FilePath -- ^ archive to extract+extract :: PathDir b0 -- ^ destination directory+        -> PathFile b1 -- ^ archive to extract         -> IO ()-extract dir archive = do+extract (toFP -> dir) (toFP -> archive) = do   createDirectoryIfMissing True dir   archive' <- makeAbsolute archive >>= parseAbsFile   dir' <- makeAbsolute dir >>= parseAbsDir
test/Example.hs view
@@ -5,6 +5,8 @@ import Path import Path.IO (ensureDir, removeDirRecur, removeFile, withSystemTempDir) +import Utilities+ main :: IO () main = mapM_ runTest   [ NoCompression@@ -16,9 +18,9 @@ runTest compression = withSystemTempDir "" $ \dir -> do   putStrLn $ "\nTesting: " ++ show compression   mapM_ (mkFile dir) files-  create compression (fromRelFile archive) $ fromAbsDir dir+  create compression (fromPath archive) (fromPath dir) -  extract (fromRelDir extractDir) $ fromRelFile archive+  extract (fromPath extractDir) (fromPath archive)   contents <- mapM (readFile . fromRelFile . (extractDir </>)) files   putStrLn $ unlines contents   unless (contents == map show files) $
test/Test.hs view
@@ -13,7 +13,6 @@     , Rel     , Path     , absdir-    , fromAbsDir     , fromAbsFile     , parent     , parseRelDir@@ -26,6 +25,8 @@ import Test.Tasty (defaultMain, testGroup) import Test.Tasty.QuickCheck (testProperty) +import Utilities+ main :: IO () main = defaultMain $ testGroup "ztar"   [ testProperty "Create/extract uncompressed tar archives" $ testZTar NoCompression@@ -56,8 +57,8 @@      -- create and extract archive     ensureDir $ parent archive'-    create compression (fromAbsFile archive') (fromAbsDir src')-    extract (fromAbsDir dest') (fromAbsFile archive')+    create compression (fromPath archive') (fromPath src')+    extract (fromPath dest') (fromPath archive')      -- check files     fmap and $ forM files $ \(path, contents) -> do
+ test/Utilities.hs view
@@ -0,0 +1,13 @@+{-# LANGUAGE CPP #-}++module Utilities where++import Path++#ifdef TYPED_PATHS+fromPath :: Path b t -> Path b t+fromPath = id+#else+fromPath :: Path b t -> FilePath+fromPath = toFilePath+#endif
ztar.cabal view
@@ -1,5 +1,5 @@ name:                ztar-version:             0.1.2+version:             0.1.3 license:             BSD3 license-file:        LICENSE.md author:              Brandon Chinn <brandonchinn178@gmail.com>@@ -20,11 +20,17 @@   manual:             True   default:            False +flag typed-paths+  description:        Use the Path library+  manual:             True+  default:            False+ library   hs-source-dirs:     src   default-language:   Haskell2010   exposed-modules:    Codec.Archive.ZTar                       Codec.Archive.ZTar.GZip+                      Codec.Archive.ZTar.Path                       Codec.Archive.ZTar.Tar                       Codec.Archive.ZTar.Zip                       Codec.Archive.Tar@@ -41,6 +47,10 @@                     , process                     , text                     , unix-compat+  if flag(typed-paths)+    build-depends:    path >= 0.5 && < 0.7+    cpp-options:      -DTYPED_PATHS+   ghc-options: -Wall   if flag(dev)     ghc-options:      -Werror@@ -56,10 +66,13 @@   default-language:   Haskell2010   hs-source-dirs:     test   main-is:            Example.hs+  other-modules:      Utilities   build-depends:      base                     , path                     , path-io                     , ztar+  if flag(typed-paths)+    cpp-options:      -DTYPED_PATHS   ghc-options: -Wall   if flag(dev)     ghc-options:      -Werror@@ -75,6 +88,7 @@   default-language:   Haskell2010   hs-source-dirs:     test   main-is:            Test.hs+  other-modules:      Utilities   build-depends:      base                     , bytestring                     , bytestring-arbitrary@@ -85,6 +99,8 @@                     , tasty                     , tasty-quickcheck                     , ztar+  if flag(typed-paths)+    cpp-options:      -DTYPED_PATHS   ghc-options: -Wall   if flag(dev)     ghc-options:      -Werror