Got the major fuctions completed

This commit is contained in:
Paul Mullins 2020-04-02 03:05:13 -04:00
parent 89de856a7c
commit 31c13127be
3 changed files with 45 additions and 0 deletions

1
compress_me.txt Normal file
View File

@ -0,0 +1 @@
Why hello there kind stranger.

44
metacompress.py Normal file
View File

@ -0,0 +1,44 @@
#!/usr/bin/env python
import os
import zipfile
# https://stackoverflow.com/questions/1855095/how-to-create-a-zip-archive-of-a-directory-in-python
def zipdir(path, ziph):
# ziph is zipfile handle
for root, dirs, files in os.walk(path):
for file in files:
ziph.write(os.path.join(root, file))
# Maybe use cwd = os.getcwd()
# https://stackoverflow.com/questions/12092527/python-write-bytes-to-file
def get_bytes_from_file(filename):
return open(filename, "rb").read()
# http://www.codecodex.com/wiki/Read_a_file_into_a_byte_array#Python
def write_bytes(write_bytes_where, mah_bytes):
f = open(write_bytes_where, 'wb')
f.write(mah_bytes)
f.close()
# https://stackoverflow.com/questions/3451111/unzipping-files-in-python
def unzip_file(file_path, output_path):
with zipfile.ZipFile(file_path, 'r') as tyler_perry:
tyler_perry.extractall(output_path)
if __name__ == '__main__':
# https://stackoverflow.com/questions/5137497/find-current-directory-and-files-directory#5137509
dir_path = os.path.dirname(os.path.realpath(__file__))
print(dir_path)
# The next four lines are from
# https://stackoverflow.com/questions/1855095/how-to-create-a-zip-archive-of-a-directory-in-python
zipf = zipfile.ZipFile('Python.zip', 'w', zipfile.ZIP_DEFLATED)
zipdir(dir_path, zipf)
zipf.close()
print('All files zipped successfully!')
some_bytes = get_bytes_from_file("Python.zip")
print(some_bytes)
write_bytes('Python2.zip', some_bytes)
unzip_file("Python.zip", "./what")
## Peach Pie is from https://ccsearch.creativecommons.org/photos/fe32017c-df1b-455c-9784-0f9b3a141717

BIN
test_folder/peach_pie.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 322 KiB