From ced94242804d987e7a2a1a3ea1ef3e892b66504e Mon Sep 17 00:00:00 2001 From: Samuel Carlsson Date: Mon, 22 Jan 2024 13:47:11 +0100 Subject: [PATCH] add windows support --- ar/archive.py | 2 +- ar/tests/test_windows.py | 52 +++++++++++++++++++++++++++++++++++++++ test_data/MiniLib.lib | Bin 0 -> 6232 bytes 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 ar/tests/test_windows.py create mode 100644 test_data/MiniLib.lib diff --git a/ar/archive.py b/ar/archive.py index f159cc0..176c651 100644 --- a/ar/archive.py +++ b/ar/archive.py @@ -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() diff --git a/ar/tests/test_windows.py b/ar/tests/test_windows.py new file mode 100644 index 0000000..c2e1be1 --- /dev/null +++ b/ar/tests/test_windows.py @@ -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" diff --git a/test_data/MiniLib.lib b/test_data/MiniLib.lib new file mode 100644 index 0000000000000000000000000000000000000000..112cb0c99dcfde3ef388b123a44e93e66cfdd5db GIT binary patch literal 6232 zcmeHLeQXrh5r4aD;}84+Mi82k@Ja}jk~`m>U1Ka%pFi&GqnLAjcjh2R*5|!F-@@MQ zvAbt%`gK6!DpK0gHkFdnCjEn^jiG@y5+aDIg;G#I)Jlz1k*H~!KakQ-wNWZnO@lkL zw|ndw+l^^R{^?lWxBK4j&6{~M@6F78Xj@VhG9RmLrcUy1@qBcv&*SyBIr}~4r?=I5 z8>uCPaD=c+2w8Rk|9Rf;=LdyMWHQV9Jsy87of(%hvCN@ddR*BtaY#}!895uv$Z2U} zJSL6rmou@PnpG8bGA8r|php=$lo^lhpU}ecw7((wl>(X78ox<(fTtp z3`tGt!RN&G8_(B$>!p(er;h*T?79t+OS>BgSy5L_aBQXy-eHH4+$mKQ^l`EDMaTra zL>cSLY-^Vhw;;*u(_`g|b7nd3>?kZiVXM&yn0*R zE$!}>7H^9uF)HN}{fef?!H3Xi1fM%4%j@VW5W%HS=EamG6IYtR$}vq;wL~PDEr>Gh zNvg7@DY=BE6jVV>sA670aSTs0yimyJi7TaO#I;8vu3e;sxU`f!prl0N3Xj1*jD$yh z#1-g=w}D>b>WdIpP}0Mr`+|j>V7>Py^(1laREDC_5bzQ@a_YE3T)PpVEKV%@p|B2$ zE10@{Cf3QygT-B<3ilfBgQ|DrRj`>(mIv?o=l5F~ylNO9cif-ySGHzpZMVzS9q~Gx@_Cl%Qwc}_{Q46>(`ptMY2az zAmdBdE@#fXa^wrsp=WA-a((B8XCFH8>)&mA@z@_SzhATWvy*>WqvdCkkOdAqN)Uw`ahQ-8|ssTQl(e|UN+`5Ect zdy=}4Nsh{56w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