{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE ViewPatterns #-}
module Codec.Archive.ZTar.Tar
( pattern TarFormat
, create
, extract
) where
import qualified Codec.Archive.Tar as Tar
import Data.ByteString.Lazy (ByteString)
import qualified Data.ByteString.Lazy as BS
pattern TarFormat :: ByteString
pattern TarFormat <- (matchesTar -> True)
matchesTar :: ByteString -> Bool
matchesTar (BS.drop 0x101 -> s) = any (`BS.isPrefixOf` s) tarMagicNumbers
where
tarMagicNumbers = map BS.pack
[ [0x75, 0x73, 0x74, 0x61, 0x72, 0x00, 0x30, 0x30]
, [0x75, 0x73, 0x74, 0x61, 0x72, 0x20, 0x20, 0x00]
]
create :: FilePath
-> FilePath
-> [FilePath]
-> IO ()
create = Tar.create
extract :: FilePath
-> FilePath
-> IO ()
extract = flip Tar.extract