Expose external attributes on zipping only

For #6 -- based on patch by @utdemir
This commit is contained in:
Dylan Simon 2018-04-24 13:49:12 -04:00
parent 33d3a06b35
commit d540ec853e
4 changed files with 5 additions and 2 deletions

View File

@ -10,7 +10,7 @@ import Data.String (IsString(..))
import qualified Data.Text as T
import Data.Time.LocalTime (LocalTime)
import Data.Typeable (Typeable)
import Data.Word (Word64)
import Data.Word (Word32, Word64)
-- |Errors thrown during zip file processing
newtype ZipError = ZipError String
@ -33,6 +33,7 @@ data ZipEntry = ZipEntry
{ zipEntryName :: Either T.Text ByteString -- ^File name (in posix format, no leading slashes), either UTF-8 encoded text or raw bytes (CP437), with a trailing slash for directories
, zipEntryTime :: LocalTime -- ^Modification time
, zipEntrySize :: Maybe Word64 -- ^Size of file data (if known); checked on zipping and also used as hint to enable zip64
, zipEntryExternalAttributes :: Maybe Word32 -- ^Host-dependent attributes, often MS-DOS directory attribute byte (only supported when zipping)
} deriving (Eq, Show)
-- |The data contents for a 'ZipEntry'. For empty entries (e.g., directories), use 'mempty'.

View File

@ -221,6 +221,7 @@ unZipStream = next where
{ zipEntryName = if testBit gpf 11 then Left (TE.decodeUtf8 name) else Right name
, zipEntryTime = time
, zipEntrySize = if testBit gpf 3 then Nothing else Just extZip64USize
, zipEntryExternalAttributes = Nothing
}
, fileDecompress = dcomp
, fileCSize = extZip64CSize

View File

@ -192,7 +192,7 @@ zipStream ZipOptions{..} = execStateC 0 $ do
P.putWord16le 0 -- comment length
P.putWord16le 0 -- disk number
P.putWord16le 0 -- internal file attributes
P.putWord32le 0 -- external file attributes
P.putWord32le $ fromMaybe 0 zipEntryExternalAttributes
P.putWord32le $ if o64 then maxBound32 else fromIntegral off
P.putByteString name
when a64 $ do

View File

@ -48,6 +48,7 @@ generate (p:paths) = do
{ zipEntryName = Right $ BSC.pack $ dropWhile ('/' ==) p
, zipEntryTime = utcToLocalTime utc t -- FIXME: timezone
, zipEntrySize = Nothing
, zipEntryExternalAttributes = Nothing
}
isd <- liftIO $ doesDirectoryExist p
if isd