Skip to content

Commit

Permalink
refactor: flags dynamic based on if encryption is used
Browse files Browse the repository at this point in the history
At the moment, encryption is never used, so this is just a refactor
  • Loading branch information
michalc committed Jan 3, 2024
1 parent 8f48f53 commit a6e0490
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions stream_zip.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,10 @@ def _zip_64_local_header_and_data(name_encoded, mod_at_ms_dos, mod_at_unix_extra
0, # Compressed size - since data descriptor
) + mod_at_unix_extra + aes_extra

flags = b'\x08\x08' # data descriptor and utf-8 file names
# (encryption,) data descriptor and utf-8 file names
flags = \
b'\x88\x08' if aes_extra else \
b'\x08\x08'

yield from _(local_header_signature)
yield from _(local_header_struct.pack(
Expand Down Expand Up @@ -209,7 +212,10 @@ def _zip_32_local_header_and_data(name_encoded, mod_at_ms_dos, mod_at_unix_extra

extra = mod_at_unix_extra + aes_extra

flags = b'\x08\x08' # data descriptor and utf-8 file names
# (encryption,) data descriptor and utf-8 file names
flags = \
b'\x88\x08' if aes_extra else \
b'\x08\x08'

yield from _(local_header_signature)
yield from _(local_header_struct.pack(
Expand Down Expand Up @@ -297,7 +303,10 @@ def _no_compression_64_local_header_and_data(name_encoded, mod_at_ms_dos, mod_at
size, # Compressed
) + mod_at_unix_extra + aes_extra

flags = b'\x00\x08' # utf-8 file names
# (encryption and) utf-8 file names
flags = \
b'\x80\x08' if aes_extra else \
b'\x00\x08'

yield from _(local_header_signature)
yield from _(local_header_struct.pack(
Expand Down Expand Up @@ -352,7 +361,10 @@ def _no_compression_32_local_header_and_data(name_encoded, mod_at_ms_dos, mod_at

chunks, size, crc_32 = _no_compression_buffered_data_size_crc_32(chunks, maximum_size=0xffffffff)

flags = b'\x00\x08' # utf-8 file names
# (encryption and) utf-8 file names
flags = \
b'\x80\x08' if aes_extra else \
b'\x00\x08'

extra = mod_at_unix_extra + aes_extra
yield from _(local_header_signature)
Expand Down Expand Up @@ -424,7 +436,10 @@ def _no_compression_streamed_64_local_header_and_data(name_encoded, mod_at_ms_do
uncompressed_size, # Compressed
) + mod_at_unix_extra + aes_extra

flags = b'\x00\x08' # utf-8 file names
# (encryption and) utf-8 file names
flags = \
b'\x80\x08' if aes_extra else \
b'\x00\x08'

yield from _(local_header_signature)
yield from _(local_header_struct.pack(
Expand Down Expand Up @@ -478,7 +493,10 @@ def _no_compression_streamed_32_local_header_and_data(name_encoded, mod_at_ms_do

extra = mod_at_unix_extra + aes_extra

flags = b'\x00\x08' # utf-8 file names
# (encryption and) utf-8 file names
flags = \
b'\x80\x08' if aes_extra else \
b'\x00\x08'

yield from _(local_header_signature)
yield from _(local_header_struct.pack(
Expand Down

0 comments on commit a6e0490

Please sign in to comment.