Skip to content

Commit

Permalink
add isal
Browse files Browse the repository at this point in the history
  • Loading branch information
StarrFox committed Dec 22, 2023
1 parent 6f432b5 commit 9473f6a
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 24 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,5 @@ result

# vscode garbage
.vscode

x
70 changes: 54 additions & 16 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ repository = "https://github.com/StarrFox/wizwad"
python = "^3.10"
click = "^8.1.7"
more-itertools = "^10.1.0"
isal = "^1.5.3"

[tool.poetry.scripts]
wizwad = "wizwad.__main__:main"
Expand Down
8 changes: 4 additions & 4 deletions wizwad/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ def extract(input_wad: Path, output_dir: Path):
@click.option(
"--compression-level",
type=int,
default=9,
help="zlib compression level of the data blob",
default=2,
help="isal compression level of the data blob",
)
def pack(
target_wad: Path,
Expand All @@ -86,8 +86,8 @@ def pack(
click.echo("workers must be greater than 0")
exit(1)

if not 1 <= compression_level <= 9:
click.echo("compression level must be 1-9")
if not 0 <= compression_level <= 3:
click.echo("compression level must be 0-3")
exit(1)

Wad.from_full_add(
Expand Down
18 changes: 14 additions & 4 deletions wizwad/wad.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
import logging
import os
import struct
import zlib
#import zlib
from dataclasses import dataclass
from io import BytesIO
from mmap import ACCESS_READ, mmap
from pathlib import Path
from typing import Iterator, List, Optional, Union

from isal import isal_zlib as zlib

import more_itertools

_NO_COMPRESS = frozenset(
Expand Down Expand Up @@ -229,7 +231,7 @@ def from_full_add(
overwrite: bool = False,
wad_version: int = 1,
workers: int = 10,
compression_level: int = 9,
compression_level: int = 2,
):
if isinstance(source_path, str):
source_path = Path(source_path)
Expand Down Expand Up @@ -257,7 +259,7 @@ def _insert_all_fast(
output_path: Path,
wad_version: int = 1,
workers: int = 100,
compression_level: int = 9,
compression_level: int = 2,
):
to_write: list[Path] = []
source_path_string = str(source_path)
Expand Down Expand Up @@ -341,7 +343,7 @@ def _calculate_chunk(
files: Iterator[Path],
start: int,
source: Path,
compression_level: int = 9,
compression_level: int = 2,
) -> tuple[int, BytesIO, list[WadFileInfo]]:
"""
returns end offset, data block, and journal entries
Expand Down Expand Up @@ -376,3 +378,11 @@ def _calculate_chunk(
data_buffer.write(data)

return current_offset, data_buffer, journal_entries


if __name__ == "__main__":
_calculate_chunk(
iter([Path("wad.py")]),
0,
Path(__file__).absolute().parent
)

0 comments on commit 9473f6a

Please sign in to comment.