Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gracefully convert .rar to .zip using Python

I'm currently making system call to "unrar and zip" commands. It interrupts and requires me to enter password while encounter password propected archives.

Is it possible to let it run and return a "unsuccessful" value to main program on any error or password prompt?

Can we natively use rarfile and zipfile library to do the job without creating any temporary files?

like image 667
jack Avatar asked Sep 21 '26 07:09

jack


1 Answers

I think it's very difficult to do the task without using temporary files. If you are converting very large files you need to use temporary space in disk.

You can use the PyUnRAR2 library, it will let you examine and extract the files of a RAR archive. You can extract the files to a temporary folder created with the tempfile python module. After that create a ZIP file using the zipfile python module.

Note that in order to use PyUnRAR2 you need the RAR proprietary binary files.

like image 121
Manuel Ceron Avatar answered Sep 23 '26 19:09

Manuel Ceron



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!