{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE ViewPatterns #-}
module Codec.Archive.ZTar.GZip
( pattern GZipFormat
, create
, extract
) where
import qualified Codec.Archive.Tar as Tar
import qualified Codec.Compression.GZip as GZ
import Data.ByteString.Lazy (ByteString)
import qualified Data.ByteString.Lazy as BS
import Codec.Archive.ZTar.Path
pattern GZipFormat :: ByteString
pattern GZipFormat <- ((BS.pack [0x1F, 0x8B] `BS.isPrefixOf`) -> True)
create :: PathFile b0
-> PathDir b1
-> [FilePath]
-> IO ()
create (toFP -> archive) (toFP -> base) paths =
BS.writeFile archive . GZ.compress . Tar.write =<< Tar.pack base paths
extract :: PathDir b0
-> PathFile b1
-> IO ()
extract (toFP -> dir) (toFP -> archive) =
Tar.unpack dir . Tar.read . GZ.decompress =<< BS.readFile archive