Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add possibility to add empty directories to archive #30

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
language: python
python:
- "2.6"
- "2.7"
- "3.2"
- "3.3"
- "3.4"
- "3.5"
- "pypy"
- "3.6"
- "3.7"
- "3.8"
- "3.9"
install:
- "pip install ."
script: nosetests
Expand Down
2 changes: 2 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Deprecated ⚠️
Moved to: https://github.com/saritasa-nest/usummit-python-zipstream

# python-zipstream

Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py26, py27, py32, py33, py34, py35, pypy
envlist = py35, py36, py37, py38, py39

[testenv]
deps=nose
Expand Down
9 changes: 7 additions & 2 deletions zipstream/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,8 @@ def __write(self, filename=None, iterable=None, arcname=None, compress_type=None
mtime = time.localtime(st.st_mtime)
date_time = mtime[0:6]
else:
st, isdir, date_time = None, False, time.localtime()[0:6]
st, date_time = None, time.localtime()[0:6]
isdir = arcname[-1] == os.sep
# Create ZipInfo instance to store file information
if arcname is None:
arcname = filename
Expand All @@ -256,7 +257,7 @@ def __write(self, filename=None, iterable=None, arcname=None, compress_type=None
if st:
zinfo.external_attr = (st[0] & 0xFFFF) << 16 # Unix attributes
else:
zinfo.external_attr = 0o600 << 16 # ?rw-------
zinfo.external_attr = 0o777 << 16 # ?drwxr-xr-x
if compress_type is None:
zinfo.compress_type = self.compression
else:
Expand All @@ -280,6 +281,10 @@ def __write(self, filename=None, iterable=None, arcname=None, compress_type=None
zinfo.file_size = 0
zinfo.compress_size = 0
zinfo.CRC = 0
# use `0` bits flag for folders - because of bug with opening
# archives with folders ZipInfo on macOS (couldn't be decompressed)
zinfo.flag_bits = 0
zinfo.external_attr |= 0x10 # MS-DOS directory flag
self.filelist.append(zinfo)
self.NameToInfo[zinfo.filename] = zinfo
yield self.fp.write(zinfo.FileHeader(False))
Expand Down