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 windows support #13

Merged
merged 1 commit into from
Jan 22, 2024
Merged
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
2 changes: 1 addition & 1 deletion ar/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def open(self, path: Union[str, ArPath], mode='r', encoding='utf-8'):

def lookup(data: bytes, offset: int) -> str:
start = offset
end = data.index(b"\n", start)
end = data.find(b"\00", start)
return data[start:end - 1].decode()


Expand Down
52 changes: 52 additions & 0 deletions ar/tests/test_windows.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# pylint: disable=redefined-outer-name
import subprocess
from pathlib import Path

import pytest

from ar import Archive, ArchiveError


ARCHIVE = Path('test_data/MiniLib.lib')


def test_list():
with ARCHIVE.open('rb') as f:
archive = Archive(f)
expected = ['x64\\Release\\pch.ob', 'x64\\Release\\MiniLib.ob']
actual = [entry.name for entry in archive]
assert actual == expected


def test_read_binary():
with ARCHIVE.open('rb') as f:
archive = Archive(f)
file0 = archive.open('x64\\Release\\MiniLib.ob', 'rb')
assert file0.read(16) == b'\x00\x00\xff\xff\x01\x00d\x86tF\xaee8\xfe\xb3\x0c'


def test_seek_basic():
with ARCHIVE.open('rb') as f:
archive = Archive(f)
file0 = archive.open('x64\\Release\\MiniLib.ob', 'rb')
file0.seek(1)
assert file0.read(3) == b'\x00\xff\xff'


def test_tell():
with ARCHIVE.open('rb') as f:
archive = Archive(f)
file0 = archive.open('x64\\Release\\MiniLib.ob', 'rb')
assert file0.tell() == 0
file0.read(2)
assert file0.tell() == 2
file0.read()
assert file0.tell() == 1887


def test_open_missing_path():
with ARCHIVE.open('rb') as f:
archive = Archive(f)
with pytest.raises(ArchiveError) as exception_info:
archive.open('missing')
assert str(exception_info.value) == "No such entry: missing"
Binary file added test_data/MiniLib.lib
Binary file not shown.