Reading from encrypted zips in Haskell using LibZip

181 Views Asked by At

I try to open encrypted zip file and then to write it again. Unfortunately I keep getting "Read error" and don't understand why. I find the documentation of LibZip for Haskell hard to follow so would be grateful for any explanation on how it works. Here is my code:

writeZip :: FilePath -> [(FilePath, ZipSource)] -> IO ()
writeZip zipName zipContent = withArchive [CreateFlag] zipName $ do
      mapM_ (uncurry addFile) zipContent


readEncryptedZip :: FilePath -> Password -> IO [(FilePath, ZipSource)]
readEncryptedZip zipName passwd = withEncryptedArchive [CheckConsFlag]   
                                                       passwd zipName $ do
      nn <- fileNames []
      ss <- mapM (\n -> sourceFile n 0 (-1)) nn
      return $ zip nn ss

and main module:

main = readEncryptedZip "protected_file2.zip" "ll" >>= writeZip "unprotected.zip"

Using Codec.Archive.LibZip, ghci version 8.0.1, MacOs Sierra 10.12

Thanks in advance!

0

There are 0 best solutions below