module Archive.Compression ( Decompressor
, Compressor
, unpackFileToDirAndDecompress
, packFromFilesAndCompress
, packFromDirAndCompress
, packSrcDirAndCompress
) where
import Archive
import qualified Data.ByteString.Lazy as BSL
import System.Directory.Recursive
type Decompressor = BSL.ByteString -> BSL.ByteString
type Compressor = BSL.ByteString -> BSL.ByteString
unpackFileToDirAndDecompress :: Decompressor
-> FilePath
-> FilePath
-> IO ()
unpackFileToDirAndDecompress f tar dir = unpackToDir dir =<< (f <$> BSL.readFile tar)
packFromDirAndCompress :: Compressor
-> FilePath
-> FilePath
-> IO ()
packFromDirAndCompress f dir tar = packFromFilesAndCompress f tar =<< getDirRecursive dir
packSrcDirAndCompress :: Compressor -> FilePath -> FilePath -> IO ()
packSrcDirAndCompress f dir tar = packFromFilesAndCompress f tar =<< getDirFiltered (pure.srcFilter) dir
srcFilter :: FilePath -> Bool
srcFilter ".git" = False
srcFilter "_dargs" = False
srcFilter ".hg" = False
srcFilter ".pijul" = False
srcFilter "dist" = False
srcFilter "dist-newstyle" = False
srcFilter ".stack-work" = False
srcFilter "target" = False
srcFilter ".atspkg" = False
srcFilter ".shake" = False
srcFilter ".vagrant" = False
srcFilter _ = False
packFromFilesAndCompress :: Compressor -> FilePath -> [FilePath] -> IO ()
packFromFilesAndCompress f tar fps = BSL.writeFile tar =<< (f <$> packFiles fps)