0

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!

Kanes115
  • 119
  • 6
  • Ctrl-Fing https://hackage.haskell.org/package/LibZip-1.0.1/src/Codec/Archive/LibZip/Types.hs for "Read Error" points at ErrREAD and c'ZIP_ER_READ, which points at https://github.com/aseprite/libzip/search?utf8=%E2%9C%93&q=ZIP_ER_READ . Now this is a C question. :P – Gurkenglas Dec 21 '16 at 14:17
  • You can try to see errno after fail, like this: `main = (readEncryptedZip "protected_file2.zip" "ll" >>= writeZip "unprotected.zip") \`catchIO\` (\e -> getErrno >>= \errno -> print (e, errno))` – freestyle Dec 21 '16 at 14:29
  • Is it the usual `with*` problem? Like in [withFile vs. openFile](http://stackoverflow.com/questions/9406463/withfile-vs-openfile). – effectfully Dec 21 '16 at 14:31
  • I haven't found 'catchIO' :/ I just found catchIOError in Foreign.C.Error. Did you mean that? Anyway, it says there is no instanse for Show Errno. – Kanes115 Dec 21 '16 at 15:52
  • Since this error comes from the C side, you should check the C library works for you (i.e. write your example program in the C library, or ensure the Haskell test suite works). Other than that, you should include the full error and a minimal zip file producing this error (hopefully you get this error with an empty zip file, which would indicate that it is not your zip file which is broken) – user2407038 Dec 22 '16 at 01:49

0 Answers0