Skip to content

Commit b060713

Browse files
author
JayDoubleu
committed
Add nested file/dir support
1 parent f863c63 commit b060713

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

zip_file/archive.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import re
23
import time
34
import sys
45
import json
@@ -30,11 +31,14 @@ def main():
3031
try:
3132
with zipfile.ZipFile(data['output_path'], mode='w') as zf:
3233
for file_path in sorted(file_paths, key=lambda d: d['filename']):
33-
file_bytes = open(file_path['filepath'],
34-
"rb").read().decode().replace('\r\n', '\n')
35-
file_bytes = file_bytes.encode()
34+
file_path = file_path['filepath']
35+
file_bytes = open(file_path, 'rb').read()
36+
file_bytes = file_bytes.replace(b'\r\n', b'\n')
37+
file_path = re.sub('^' + data['source_dir'], '', file_path)
38+
file_path = re.sub('^' + '/', '', file_path)
39+
file_path = re.sub('^' + r'\\', '', file_path)
3640
info = zipfile.ZipInfo(
37-
str(file_path['filename']),
41+
str(file_path),
3842
date_time=(1980, 1, 1, 00, 00, 00),
3943
)
4044
info.compress_type = zipfile.ZIP_DEFLATED

0 commit comments

Comments
 (0)