packages feed

ztar 0.1.3 → 0.2.0

raw patch · 13 files changed

+165/−224 lines, 13 filesdep ~path

Dependency ranges changed: path

Files

CHANGELOG.md view
@@ -1,3 +1,12 @@+# ztar 0.2.0++Breaking changes:+* `create'` is now `createFrom`++Changes:+* Removed the `typed-paths` flag+* Added `create'`, `createFrom'`, and `extract'` which use Path types+ # ztar 0.1.3  Changes:
+ LICENSE view
@@ -0,0 +1,11 @@+Copyright 2018 Brandon Chinn++Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:++1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.++2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.++3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
− LICENSE.md
@@ -1,11 +0,0 @@-Copyright 2018 Brandon Chinn--Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:--1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.--2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.--3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.--THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
README.md view
@@ -10,7 +10,7 @@ import Codec.Archive.ZTar  -- equivalent to `Codec.Archive.Tar.create "archive.tar" "dist/" ["."]`-create' NoCompression "archive.tar" "dist/" ["."]+createFrom NoCompression "archive.tar" "dist/" ["."]  -- helper to compress a single directory; equivalent to previous line create NoCompression "archive.tar" "dist/"@@ -22,28 +22,15 @@ create Zip "archive.zip" "dist/"  -- automatically determines compression-extract "archive-tar/" "archive.tar"-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+extract "archive.tar" "archive-tar/"+extract "archive.tar.gz" "archive-gz/"+extract "archive.zip" "archive-zip/" -# Main.hs+-- can also use Path types import Path import Path.IO- home <- getHomeDir let archive = home </> [relfile|archive.tgz|] dir <- resolveDir "dist/"-create GZip archive dir+create' GZip archive dir ```
src/Codec/Archive/ZTar.hs view
@@ -15,13 +15,16 @@   ( Compression(..)   , create   , create'+  , createFrom+  , createFrom'   , extract+  , extract'   ) where  import qualified Data.ByteString.Lazy as BS+import Path (Dir, File, Path, toFilePath)  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 @@ -34,29 +37,42 @@  -- | Create a new archive from the given directory using the given compression algorithm. create :: Compression-       -> PathFile b0 -- ^ archive file to create-       -> PathDir b1 -- ^ directory to archive+       -> FilePath -- ^ archive file to create+       -> FilePath -- ^ directory to archive        -> IO ()-create compression archive dir = create' compression archive dir ["."]+create compression archive dir = createFrom compression archive dir ["."] +-- | Same as 'create' but using Path types.+create' :: Compression -> Path b0 File -> Path b1 Dir -> IO ()+create' compression (toFilePath -> archive) (toFilePath -> dir) = create compression archive dir+ -- | Create a new archive from the given paths using the given compression algorithm.-create' :: Compression-        -> 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+createFrom :: Compression+           -> FilePath -- ^ archive file to create+           -> FilePath -- ^ base directory+           -> [FilePath] -- ^ files and paths to compress, relative to base directory+           -> IO ()+createFrom compression = case compression of   NoCompression -> Tar.create   GZip -> GZip.create   Zip -> Zip.create +-- | Same as 'createFrom' but using Path types.+createFrom' :: Compression -> Path b0 File -> Path b1 Dir -> [FilePath] -> IO ()+createFrom' compression (toFilePath -> archive) (toFilePath -> dir) paths =+  createFrom compression archive dir paths+ -- | Extract an archive to the given directory. Automatically detects the compression algorithm. -- used in the archive.-extract :: PathDir b0 -- ^ destination directory-        -> PathFile b1 -- ^ archive to extract+extract :: FilePath -- ^ archive to extract+        -> FilePath -- ^ destination directory         -> IO ()-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: " ++ (toFP archive)+extract archive dir = BS.readFile archive >>= \case+  Tar.TarFormat -> Tar.extract archive dir+  GZip.GZipFormat -> GZip.extract archive dir+  Zip.ZipFormat -> Zip.extract archive dir+  _ -> fail $ "Could not recognize archive format: " ++ archive++-- | Same as 'extract' but using Path types.+extract' :: Path b1 File -> Path b0 Dir -> IO ()+extract' (toFilePath -> archive) (toFilePath -> dir) = extract archive dir
src/Codec/Archive/ZTar/GZip.hs view
@@ -21,8 +21,6 @@ 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)@@ -32,11 +30,11 @@ -- It is equivalent to calling the standard 'tar' program like so: -- -- @$ tar -czf archive -C base paths@-create :: PathFile b0 -- ^ archive to create-       -> PathDir b1 -- ^ base directory+create :: FilePath -- ^ archive to create+       -> FilePath -- ^ base directory        -> [FilePath] -- ^ files and paths to compress, relative to base directory        -> IO ()-create (toFP -> archive) (toFP -> base) paths =+create archive base paths =   BS.writeFile archive . GZ.compress . Tar.write =<< Tar.pack base paths  -- | Extract all the files contained in an archive compressed with GZip.@@ -44,8 +42,8 @@ -- It is equivalent to calling the standard 'tar' program like so: -- -- @$ tar -xf archive -C dir@-extract :: PathDir b0 -- ^ destination directory-        -> PathFile b1 -- ^ archive to extract+extract :: FilePath -- ^ archive to extract+        -> FilePath -- ^ destination directory         -> IO ()-extract (toFP -> dir) (toFP -> archive) =+extract archive dir =   Tar.unpack dir . Tar.read . GZ.decompress =<< BS.readFile archive
− src/Codec/Archive/ZTar/Path.hs
@@ -1,37 +0,0 @@-{-|-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
@@ -21,8 +21,6 @@ import Data.ByteString.Lazy (ByteString) import qualified Data.ByteString.Lazy as BS -import Codec.Archive.ZTar.Path- -- | A pattern matching any ByteString in an uncompressed TAR format. pattern TarFormat :: ByteString pattern TarFormat <- (matchesTar -> True)@@ -40,18 +38,18 @@ -- It is equivalent to calling the standard 'tar' program like so: -- -- @$ tar -cf archive -C base paths@-create :: PathFile b0 -- ^ archive to create-       -> PathDir b1 -- ^ base directory+create :: FilePath -- ^ archive to create+       -> FilePath -- ^ base directory        -> [FilePath] -- ^ files and paths to compress, relative to base directory        -> IO ()-create (toFP -> archive) (toFP -> base) paths = Tar.create archive base paths+create = Tar.create  -- | 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 :: PathDir b0 -- ^ destination directory-        -> PathFile b1 -- ^ archive to extract+extract :: FilePath -- ^ archive to extract+        -> FilePath -- ^ destination directory         -> IO ()-extract (toFP -> dir) (toFP -> archive) = Tar.extract dir archive+extract = flip Tar.extract
src/Codec/Archive/ZTar/Zip.hs view
@@ -32,8 +32,6 @@     ) 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)@@ -43,11 +41,11 @@ -- It is equivalent to calling the standard 'zip' program like so: -- -- @$ CURR=$PWD; (cd base && zip -r archive paths && mv archive $CURR)@-create :: PathFile b0 -- ^ archive to create-       -> PathDir b1 -- ^ base directory+create :: FilePath -- ^ archive to create+       -> FilePath -- ^ base directory        -> [FilePath] -- ^ files and paths to compress, relative to base directory        -> IO ()-create (toFP -> archive) (toFP -> base) paths = do+create archive base paths = do   archive' <- makeAbsolute archive >>= parseAbsFile   withCurrentDirectory base $ Zip.createArchive archive' $ mapM_ insert paths   where@@ -71,10 +69,10 @@ -- It is equivalent to calling the standard 'zip' program like so: -- -- @$ mkdir -p dir && unzip archive -d dir@-extract :: PathDir b0 -- ^ destination directory-        -> PathFile b1 -- ^ archive to extract+extract :: FilePath -- ^ archive to extract+        -> FilePath -- ^ destination directory         -> IO ()-extract (toFP -> dir) (toFP -> archive) = do+extract archive dir = do   createDirectoryIfMissing True dir   archive' <- makeAbsolute archive >>= parseAbsFile   dir' <- makeAbsolute dir >>= parseAbsDir
test/Example.hs view
@@ -5,8 +5,6 @@ import Path import Path.IO (ensureDir, removeDirRecur, removeFile, withSystemTempDir) -import Utilities- main :: IO () main = mapM_ runTest   [ NoCompression@@ -18,9 +16,9 @@ runTest compression = withSystemTempDir "" $ \dir -> do   putStrLn $ "\nTesting: " ++ show compression   mapM_ (mkFile dir) files-  create compression (fromPath archive) (fromPath dir)+  create' compression archive dir -  extract (fromPath extractDir) (fromPath archive)+  extract' archive extractDir   contents <- mapM (readFile . fromRelFile . (extractDir </>)) files   putStrLn $ unlines contents   unless (contents == map show files) $
test/Test.hs view
@@ -25,8 +25,6 @@ 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@@ -57,8 +55,8 @@      -- create and extract archive     ensureDir $ parent archive'-    create compression (fromPath archive') (fromPath src')-    extract (fromPath dest') (fromPath archive')+    create' compression archive' src'+    extract' archive' dest'      -- check files     fmap and $ forM files $ \(path, contents) -> do
− test/Utilities.hs
@@ -1,13 +0,0 @@-{-# 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,112 +1,101 @@-name:                ztar-version:             0.1.3-license:             BSD3-license-file:        LICENSE.md-author:              Brandon Chinn <brandonchinn178@gmail.com>-maintainer:          Brandon Chinn <brandonchinn178@gmail.com>-category:            Codec-synopsis:            Creating and extracting arbitrary archives-description:         Creating and extracting arbitrary archives.-build-type:          Simple-cabal-version:       1.18-extra-doc-files:     CHANGELOG.md, README.md+-- This file has been generated from package.yaml by hpack version 0.28.2.+--+-- see: https://github.com/sol/hpack+--+-- hash: c39489aefc941fc38bd650d9f61d4cfbc64a46eb644a01468a3c27fad9de23b4 +name:           ztar+version:        0.2.0+synopsis:       Creating and extracting arbitrary archives+description:    Creating and extracting arbitrary archives.+category:       Codec+homepage:       https://github.com/brandonchinn178/ztar#readme+bug-reports:    https://github.com/brandonchinn178/ztar/issues+author:         Brandon Chinn <brandonchinn178@gmail.com>+maintainer:     Brandon Chinn <brandonchinn178@gmail.com>+license:        BSD3+license-file:   LICENSE+build-type:     Simple+cabal-version:  >= 1.18+extra-doc-files:+    CHANGELOG.md+    README.md+ source-repository head   type: git-  location: https://github.com/brandonchinn178/ztar.git+  location: https://github.com/brandonchinn178/ztar  flag dev-  description:        Turn on development settings.-  manual:             True-  default:            False--flag typed-paths-  description:        Use the Path library-  manual:             True-  default:            False+  description: Turn on development settings.+  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-  build-depends:      base >= 4.7 && < 5-                    , bytestring >= 0.10.8 && < 0.11-                    , directory >= 1.3 && < 1.4-                    , filepath >= 1.4.1 && < 1.5-                    , path-                    -- , tar >= 0.5 && < 0.6-                    , zip >= 0.2 && < 0.3-                    , zlib >= 0.6 && < 0.7-                    -- For Codec.Archive.Tar-                    , deepseq-                    , process-                    , text-                    , unix-compat-  if flag(typed-paths)-    build-depends:    path >= 0.5 && < 0.7-    cpp-options:      -DTYPED_PATHS-+  exposed-modules:+      Codec.Archive.Tar+      Codec.Archive.ZTar+      Codec.Archive.ZTar.GZip+      Codec.Archive.ZTar.Tar+      Codec.Archive.ZTar.Zip+  other-modules:+      Paths_ztar+  hs-source-dirs:+      src   ghc-options: -Wall+  build-depends:+      base >=4.7 && <5+    , bytestring >=0.10.8 && <0.11+    , deepseq+    , directory >=1.3 && <1.4+    , filepath >=1.4.1 && <1.5+    , path >=0.5 && <0.7+    , process+    , text+    , unix-compat+    , zip >=0.2 && <0.3+    , zlib >=0.6 && <0.7   if flag(dev)-    ghc-options:      -Werror-  if flag(dev) && impl(ghc >= 8.0)-    ghc-options:      -Wcompat-                      -Wincomplete-record-updates-                      -Wincomplete-uni-patterns-                      -Wnoncanonical-monad-instances-                      -Wnoncanonical-monadfail-instances+    ghc-options: -Werror+  if impl(ghc >= 8.0)+    ghc-options: -Wcompat -Wincomplete-record-updates -Wincomplete-uni-patterns -Wnoncanonical-monad-instances -Wnoncanonical-monadfail-instances+  default-language: Haskell2010  test-suite example-  type:               exitcode-stdio-1.0-  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+  type: exitcode-stdio-1.0+  main-is: Example.hs+  hs-source-dirs:+      test   ghc-options: -Wall+  build-depends:+      base+    , path+    , path-io+    , ztar   if flag(dev)-    ghc-options:      -Werror-  if flag(dev) && impl(ghc >= 8.0)-    ghc-options:      -Wcompat-                      -Wincomplete-record-updates-                      -Wincomplete-uni-patterns-                      -Wnoncanonical-monad-instances-                      -Wnoncanonical-monadfail-instances+    ghc-options: -Werror+  if impl(ghc >= 8.0)+    ghc-options: -Wcompat -Wincomplete-record-updates -Wincomplete-uni-patterns -Wnoncanonical-monad-instances -Wnoncanonical-monadfail-instances+  default-language: Haskell2010  test-suite ztar-test-  type:               exitcode-stdio-1.0-  default-language:   Haskell2010-  hs-source-dirs:     test-  main-is:            Test.hs-  other-modules:      Utilities-  build-depends:      base-                    , bytestring-                    , bytestring-arbitrary-                    , extra-                    , path-                    , path-io-                    , QuickCheck-                    , tasty-                    , tasty-quickcheck-                    , ztar-  if flag(typed-paths)-    cpp-options:      -DTYPED_PATHS+  type: exitcode-stdio-1.0+  main-is: Test.hs+  hs-source-dirs:+      test   ghc-options: -Wall+  build-depends:+      QuickCheck+    , base+    , bytestring+    , bytestring-arbitrary+    , extra+    , path+    , path-io+    , tasty+    , tasty-quickcheck+    , ztar   if flag(dev)-    ghc-options:      -Werror-  if flag(dev) && impl(ghc >= 8.0)-    ghc-options:      -Wcompat-                      -Wincomplete-record-updates-                      -Wincomplete-uni-patterns-                      -Wnoncanonical-monad-instances-                      -Wnoncanonical-monadfail-instances+    ghc-options: -Werror+  if impl(ghc >= 8.0)+    ghc-options: -Wcompat -Wincomplete-record-updates -Wincomplete-uni-patterns -Wnoncanonical-monad-instances -Wnoncanonical-monadfail-instances+  default-language: Haskell2010