Skip to content

Commit 214bf54

Browse files
committed
-
1 parent 40a0b98 commit 214bf54

File tree

3 files changed

+39
-4
lines changed

3 files changed

+39
-4
lines changed

source_py3/python_toolbox/zip_tools.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import zipfile as zip_module
88
import io
9+
import os
910
import re
1011
import pathlib
1112
import fnmatch
@@ -35,10 +36,10 @@ def zip_folder(source_folder, zip_path, ignored_patterns=()):
3536

3637
internal_pure_path = pathlib.PurePath(source_folder.name)
3738

38-
with zip_module.ZipFile(zip_path, 'w', zip_module.ZIP_DEFLATED) \
39+
with zip_module.ZipFile(str(zip_path), 'w', zip_module.ZIP_DEFLATED) \
3940
as zip_file:
4041

41-
for root, subfolders, files in os.walk(source_folder):
42+
for root, subfolders, files in os.walk(str(source_folder)):
4243
root = pathlib.Path(root)
4344
subfolders = map(pathlib.Path, subfolders)
4445
files = map(pathlib.Path, files)
@@ -54,7 +55,8 @@ def zip_folder(source_folder, zip_path, ignored_patterns=()):
5455
destination_file_path = internal_pure_path / \
5556
absolute_file_path.name
5657

57-
zip_file.write(absolute_file_path, destination_file_path)
58+
zip_file.write(str(absolute_file_path),
59+
str(destination_file_path))
5860

5961

6062
def zip_in_memory(files):
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Copyright 2009-2014 Ram Rachum.
2+
# This program is distributed under the MIT license.
3+
4+
import pathlib
5+
6+
from python_toolbox import cute_testing
7+
from python_toolbox import temp_file_tools
8+
9+
from python_toolbox import zip_tools
10+
11+
12+
def test():
13+
''' '''
14+
with temp_file_tools.create_temp_folder() as temp_folder:
15+
assert isinstance(temp_folder, pathlib.Path)
16+
17+
folder_to_zip = (temp_folder / 'folder_to_zip')
18+
folder_to_zip.mkdir()
19+
assert isinstance(folder_to_zip, pathlib.Path)
20+
21+
(folder_to_zip / 'some_file.txt').open('w').write('hello there!')
22+
(folder_to_zip / 'some_other_file.txt').open('w').write(
23+
'hello there again!')
24+
25+
zip_file_path = temp_folder / 'archive.zip'
26+
assert isinstance(zip_file_path, pathlib.Path)
27+
zip_tools.zip_folder(folder_to_zip, temp_folder / 'archive.zip')
28+
29+
assert zip_file_path.is_file()
30+
assert zip_tools.unzip_in_memory(zip_file_path.open('rb').read()) == (
31+
('folder_to_zip/some_file.txt', b'hello there!'),
32+
('folder_to_zip/some_other_file.txt', b'hello there again!'),
33+
)

source_py3/test_python_toolbox/test_zip_tools/test.py renamed to source_py3/test_python_toolbox/test_zip_tools/test_zipping_in_memory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from python_toolbox import zip_tools
77

88

9-
def test_zipping_in_memory():
9+
def test():
1010
''' '''
1111
files = (
1212
('meow.txt', b"I'm a cat."),

0 commit comments

Comments
 (0)