🗜️ archive#
Zips the generated datapack and resource pack.
- TEXT_EXTENSIONS: frozenset[str] = frozenset({'.fsh', '.glsl', '.json', '.lang', '.map', '.mcfunction', '.mcmeta', '.md', '.properties', '.snbt', '.txt', '.vsh', '.yaml', '.yml'})[source]#
Extensions whose entries hold text, so their line endings are normalized on the way into the archive. Everything else is archived byte for byte, since a CRLF inside a .png or an .ogg is data rather than a line ending.
- BEFORE_NEWLINE: Pattern[bytes] = re.compile(b'\\r+\\n')[source]#
Carriage returns opening a line ending, however many of them there are. A file welded out of a library archive already holding CRLF reaches this as CRCRLF. TextIOWrapper translates the newline it finds behind the carriage return that was already there.
- get_consistent_timestamp(
- ctx: Context,
Date written on every archive entry: the last commit of the beet config, in UTC, identical in every clone.
A file modification time is not kept by git, so it is only the fallback: the beet cache one, then 2025-01-01.
- class ConstantTimeZipFile(
- file: Any,
- mode: Literal['r', 'w', 'x', 'a'] = 'r',
- *args: Any,
- date_time: tuple[int, int, int, int, int, int],
- skip_names: tuple[str, ...] = (),
- **kwargs: Any,
Bases:
ZipFileZipFile that forces a constant timestamp and normalized metadata on every entry.
Replaces the old two-pass approach (dump to zip, read everything back, re-deflate with fixed timestamps): every write path used by
pack.dump()(open(mode="w"),writestrandwrite) goes through a freshZipInfocarrying the constantdate_time, so a single compression pass produces the exact same bytes.Entries whose name is in
skip_namesare silently dropped (used to replacepack.mcmeta/pack.pngwith fixed content afterwards viaforce_writestr()).A text entry is written with Unix line endings whatever the host would have used, see
unix_newlines().When the archive replaces one written before, an entry holding the same bytes as there is copied still compressed instead of being deflated again, see
store().- previous: ZipFile | None[source]#
The archive this one replaces, read before it was truncated, to reuse its unchanged entries.
- force_writestr(
- name: str,
- data: bytes,
Write an entry with the constant timestamp, bypassing
skip_names.Drops
namefromskip_namesfirst:ZipFile.writestrinternally goes throughself.openwhich would otherwise discard the entry again.
- store(name: str, data: bytes) None[source]#
Write one entry, with Unix line endings for text, reusing its compressed bytes from the previous archive when unchanged.
Deflate gives the same bytes for the same input, so the copy is what compressing again would have written. The previous entry is decompressed and compared whole: a matching checksum alone is not trusted.
- class EntryWriter(
- archive: ConstantTimeZipFile,
- name: str,
Bases:
BytesIOCollects what is written to one entry, and stores it in the archive once closed.
>>> archive = ConstantTimeZipFile(io.BytesIO(), "w", date_time=(2025, 1, 1, 0, 0, 0)) >>> with archive.open("say.mcfunction", "w") as entry: ... _ = entry.write(b"say a\r\nsay b\r\r\n") >>> archive.read("say.mcfunction") b'say a\nsay b\n'
- is_text_entry(name: str) bool[source]#
Whether an archive entry holds text, so its line endings are ours to normalize.
>>> is_text_entry("data/ns/function/tick.mcfunction"), is_text_entry("pack.png") (True, False)
- unix_lines(data: bytes) bytes[source]#
The same bytes with every line ending turned into a LF.
bytes.replaceruns eleven times faster than the pattern. It covers the CRLF a WindowsTextIOWrapperwrites, which is all but every entry of an archive built here. The pattern is only there for a run of carriage returns, which nothing but a welded library archive produces.>>> unix_lines(b"say a\r\nsay b\r\r\n") b'say a\nsay b\n'
- unix_newlines(name: str, data: str | bytes) str | bytes[source]#
The same data with every line ending turned into a LF, for a text entry only.
>>> unix_newlines("tick.mcfunction", b"say a\r\nsay b\r\r\n"), unix_newlines("icon.png", b"\r\n") (b'say a\nsay b\n', b'\r\n')
- beet_default(ctx: Context) None[source]#
Archive plugin for StewBeet. Creates zip archives of the generated datapack and resource pack using pack.dump() to avoid interfering with existing pack directories.
- Parameters:
ctx – The beet context.