Skip to content

Commit

Permalink
feat: add struct_timestamps option
Browse files Browse the repository at this point in the history
  • Loading branch information
frederikaalund committed Apr 12, 2024
1 parent c8a4503 commit f8a9d51
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions stream_zip.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from collections import deque
from datetime import datetime
from struct import Struct
import asyncio
import secrets
Expand Down Expand Up @@ -73,6 +74,7 @@ def method_compressobj(offset, default_get_compressobj):
def stream_zip(files, chunk_size=65536,
get_compressobj=lambda: zlib.compressobj(wbits=-zlib.MAX_WBITS, level=9),
extended_timestamps=True,
strict_timestamps=True,
password=None,
get_crypto_random=lambda num_bytes: secrets.token_bytes(num_bytes),
):
Expand Down Expand Up @@ -612,6 +614,12 @@ def _no_compression_streamed_data(chunks, uncompressed_size, crc_32, maximum_siz
name_encoded = name.encode('utf-8')
_raise_if_beyond(len(name_encoded), maximum=0xffff, exception_class=NameLengthOverflowError)

if not strict_timestamps:
if modified_at.year < 1980:
modified_at = datetime(1980, 1, 1, 0, 0, 0)
elif modified_at.year > 2107:
modified_at = datetime(2107, 12, 31, 23, 59, 59)

mod_at_ms_dos = modified_at_struct.pack(
int(modified_at.second / 2) | \
(modified_at.minute << 5) | \
Expand Down

0 comments on commit f8a9d51

Please sign in to comment.