    -- |
    -- Module      :  Codec.Archive.Zip.Unix
    -- Copyright   :  © 2016–present Mark Karpov
    -- License     :  BSD 3 clause
    --
    -- Maintainer  :  Mark Karpov <markkarpov92@gmail.com>
    -- Stability   :  experimental
    -- Portability :  portable
    --
    -- Unix-specific functionality of zip archives.
    --
    -- @since 1.4.0
    module Codec.Archive.Zip.Unix
      ( toFileMode,
        fromFileMode,
      )
    where

    import Data.Bits
    import Data.Word
    import System.Posix.Types (CMode (..))

    -- | Convert external attributes to the file info.
    --
    -- >>> toFileMode 2179792896
    -- 0o0755
    --
    -- @since 1.4.0
    toFileMode :: Word32 -> CMode
    toFileMode :: Word32 -> CMode
    toFileMode Word32
    attrs = Word32 -> CMode
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral (Word32 -> CMode) -> Word32 -> CMode
    forall a b. (a -> b) -> a -> b
    $ (Word32
    attrs Word32 -> Int -> Word32
    forall a. Bits a => a -> Int -> a
    `shiftR` Int
    16) Word32 -> Word32 -> Word32
    forall a. Bits a => a -> a -> a
    .&. Word32
    0x0fff

    -- | Convert external attributes to the file info. The function assumes a
    -- regular file and keeps DOS attributes untouched.
    --
    -- >>> fromFileMode 0o0755
    -- 2179792896
    --
    -- @since 1.4.0
    fromFileMode :: CMode -> Word32
    fromFileMode :: CMode -> Word32
    fromFileMode CMode
    cmode = (Word32
    0o100000 Word32 -> Word32 -> Word32
    forall a. Bits a => a -> a -> a
    .|. CMode -> Word32
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral CMode
    cmode) Word32 -> Int -> Word32
    forall a. Bits a => a -> Int -> a
    `shiftL` Int
    16