In this section, we are going to learn about the make_archive() function of the shutil module, which will compress an entire directory. For that, we are going to write a compress_a_directory.py script and write the following content in it:
import shutil
shutil.make_archive('work', 'zip', 'work/')
Run the script as follows:
$ python3 compress_a_directory.py
In the preceding script, in shutil.make_archive() function, we passed the first argument as a name to our compressed file. zip will be our compression technique. And the, work/ will be the name of the directory that we want to compress.
Now, to restore the data from the compressed file, we are going to use the unpack_archive() function from the shutil module. Create an unzip_a_directory.py script and write the following content in it:
import shutil
shutil.unpack_archive(...