Skip to content

Commit 0c76e2a

Browse files
authored
perf: export symbols in pybit7z instead of raw _core (#21)
Signed-off-by: l.feng <[email protected]>
1 parent d65a326 commit 0c76e2a

File tree

4 files changed

+254
-84
lines changed

4 files changed

+254
-84
lines changed

README.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ pip install pybit7z
4040
### Extract Files from an Archive
4141

4242
```python
43-
from pybit7z import core
43+
import pybit7z
4444

4545
try:
46-
extractor = core.BitFileExtractor(core.FormatSevenZip)
46+
extractor = pybit7z.BitFileExtractor(pybit7z.FormatSevenZip)
4747
extractor.extract("path/to/archive.7z", "out/dir/")
4848

4949
# Extracting a specific file inside an archive
@@ -55,35 +55,35 @@ try:
5555
# Extracting an encrypted archive
5656
extractor.set_password("password")
5757
extractor.extract("path/to/another/archive.7z", "out/dir/")
58-
except core.BitException as e:
58+
except pybit7z.BitException as e:
5959
... # handle the exception
6060
```
6161

6262
Work on a single archive:
6363

6464
```python
65-
from pybit7z import core
65+
import pybit7z
6666

6767
try:
6868
# Opening the archive
69-
archive = core.BitArchiveReader("path/to/archive.gz", core.FormatGZip)
69+
archive = pybit7z.BitArchiveReader("path/to/archive.gz", pybit7z.FormatGZip)
7070

7171
# Testing the archive
7272
archive.test()
7373

7474
# Extracting the archive
7575
archive.extract_to("out/dir/")
76-
except core.BitException as e:
76+
except pybit7z.BitException as e:
7777
... # handle the exception
7878
```
7979

8080
### Compress Files into an Archive
8181

8282
```python
83-
from pybit7z import core
83+
import pybit7z
8484

8585
try:
86-
compressor = core.BitFileCompressor(core.FormatSevenZip)
86+
compressor = pybit7z.BitFileCompressor(pybit7z.FormatSevenZip)
8787

8888
files = ["path/to/file1.jpg", "path/to/file2.pdf"]
8989

@@ -105,41 +105,41 @@ try:
105105
compressor.compress_files(files, "protected_archive.zip")
106106

107107
# Updating an existing zip archive
108-
compressor.set_update_mode(core.UpdateMode.Append)
108+
compressor.set_update_mode(pybit7z.UpdateMode.Append)
109109
compressor.compress_files(files, "existing_archive.zip")
110110

111111
# Compressing a single file into a buffer
112-
compressor2 = core.BitFileCompressor(core.FormatBZip2)
112+
compressor2 = pybit7z.BitFileCompressor(pybit7z.FormatBZip2)
113113
buffer: bytes = compressor2.compress_file(files[0])
114-
except core.BitException as e:
114+
except pybit7z.BitException as e:
115115
... # handle the exception
116116
```
117117

118118
Work on a single archive:
119119

120120
```python
121-
from pybit7z import core
121+
import pybit7z
122122

123123
try:
124-
archive = core.BitArchiveWriter(core.FormatSevenZip)
124+
archive = pybit7z.BitArchiveWriter(pybit7z.FormatSevenZip)
125125

126126
# Adding the items to be compressed (no compression is performed here)
127127
archive.add_file("path/to/file.txt")
128128
archive.add_directory("path/to/dir/")
129129

130130
# Compressing the added items to the output archive
131131
archive.compress_to("output.7z")
132-
except core.BitException as e:
132+
except pybit7z.BitException as e:
133133
... # handle the exception
134134
```
135135

136136
### Read Archive Metadata
137137

138138
```python
139-
from pybit7z import core
139+
import pybit7z
140140

141141
try:
142-
arc = core.BitArchiveReader("archive.7z", core.FormatSevenZip)
142+
arc = pybit7z.BitArchiveReader("archive.7z", pybit7z.FormatSevenZip)
143143

144144
# Printing archive metadata
145145
print("Archive properties:",
@@ -160,7 +160,7 @@ try:
160160
"\n Size: " , item.size(),
161161
"\n Packed size: " , item.pack_size(),
162162
"\n CRC: " , item.crc())
163-
except core.BitException as e:
163+
except pybit7z.BitException as e:
164164
... # handle the exception
165165
```
166166

docs/api/index.md

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,3 @@
66
:undoc-members:
77
:show-inheritance:
88
```
9-
10-
## Submodules
11-
12-
```{eval-rst}
13-
.. automodule:: pybit7z._core
14-
:members:
15-
:undoc-members:
16-
:show-inheritance:
17-
```

src/pybit7z/__init__.py

Lines changed: 186 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,199 @@
66

77
from __future__ import annotations
88

9-
from pathlib import Path
9+
import pathlib
1010

1111
from importlib_metadata import distribution
1212

13-
from pybit7z import _core as core
13+
from pybit7z._core import (
14+
BitAbstractArchiveCreator,
15+
BitAbstractArchiveHandler,
16+
BitAbstractArchiveOpener,
17+
BitArchiveEditor,
18+
BitArchiveItem,
19+
BitArchiveItemInfo,
20+
BitArchiveItemOffset,
21+
BitArchiveReader,
22+
BitArchiveWriter,
23+
BitCompressionLevel,
24+
BitCompressionMethod,
25+
BitException,
26+
BitFileCompressor,
27+
BitFileExtractor,
28+
BitGenericItem,
29+
BitInFormat,
30+
BitInOutFormat,
31+
BitInputArchive,
32+
BitMemCompressor,
33+
BitMemExtractor,
34+
BitOutputArchive,
35+
BitProperty,
36+
BitPropVariant,
37+
BitPropVariantType,
38+
BitStringCompressor,
39+
BitStringExtractor,
40+
DeletePolicy,
41+
FilterPolicy,
42+
FormatAPM,
43+
FormatArj,
44+
FormatAuto,
45+
FormatBZip2,
46+
FormatCab,
47+
FormatChm,
48+
FormatCoff,
49+
FormatCompound,
50+
FormatCpio,
51+
FormatCramFS,
52+
FormatDeb,
53+
FormatDmg,
54+
FormatElf,
55+
FormatExt,
56+
FormatFat,
57+
FormatFeatures,
58+
FormatFlv,
59+
FormatGpt,
60+
FormatGZip,
61+
FormatHfs,
62+
FormatHxs,
63+
FormatIHex,
64+
FormatIso,
65+
FormatLzh,
66+
FormatLzma,
67+
FormatLzma86,
68+
FormatMacho,
69+
FormatMbr,
70+
FormatMslz,
71+
FormatMub,
72+
FormatNsis,
73+
FormatNtfs,
74+
FormatPe,
75+
FormatPpmd,
76+
FormatQcow,
77+
FormatRar,
78+
FormatRar5,
79+
FormatRpm,
80+
FormatSevenZip,
81+
FormatSplit,
82+
FormatSquashFS,
83+
FormatSwf,
84+
FormatSwfc,
85+
FormatTar,
86+
FormatTE,
87+
FormatUdf,
88+
FormatUEFIc,
89+
FormatUEFIs,
90+
FormatVdi,
91+
FormatVhd,
92+
FormatVhdx,
93+
FormatVmdk,
94+
FormatWim,
95+
FormatXar,
96+
FormatXz,
97+
FormatZ,
98+
FormatZip,
99+
OverwriteMode,
100+
UpdateMode,
101+
set_large_page_mode,
102+
set_lib7zip_path,
103+
)
14104

15105
from ._version import version as __version__
16106

17-
__all__ = ["__version__", "core"]
107+
__all__ = [
108+
"BitAbstractArchiveCreator",
109+
"BitAbstractArchiveHandler",
110+
"BitAbstractArchiveOpener",
111+
"BitArchiveEditor",
112+
"BitArchiveItem",
113+
"BitArchiveItemInfo",
114+
"BitArchiveItemOffset",
115+
"BitArchiveReader",
116+
"BitArchiveWriter",
117+
"BitCompressionLevel",
118+
"BitCompressionMethod",
119+
"BitException",
120+
"BitFileCompressor",
121+
"BitFileExtractor",
122+
"BitGenericItem",
123+
"BitInFormat",
124+
"BitInOutFormat",
125+
"BitInputArchive",
126+
"BitMemCompressor",
127+
"BitMemExtractor",
128+
"BitOutputArchive",
129+
"BitPropVariant",
130+
"BitPropVariantType",
131+
"BitProperty",
132+
"BitStringCompressor",
133+
"BitStringExtractor",
134+
"DeletePolicy",
135+
"FilterPolicy",
136+
"FormatAPM",
137+
"FormatArj",
138+
"FormatAuto",
139+
"FormatBZip2",
140+
"FormatCab",
141+
"FormatChm",
142+
"FormatCoff",
143+
"FormatCompound",
144+
"FormatCpio",
145+
"FormatCramFS",
146+
"FormatDeb",
147+
"FormatDmg",
148+
"FormatElf",
149+
"FormatExt",
150+
"FormatFat",
151+
"FormatFeatures",
152+
"FormatFlv",
153+
"FormatGZip",
154+
"FormatGpt",
155+
"FormatHfs",
156+
"FormatHxs",
157+
"FormatIHex",
158+
"FormatIso",
159+
"FormatLzh",
160+
"FormatLzma",
161+
"FormatLzma86",
162+
"FormatMacho",
163+
"FormatMbr",
164+
"FormatMslz",
165+
"FormatMub",
166+
"FormatNsis",
167+
"FormatNtfs",
168+
"FormatPe",
169+
"FormatPpmd",
170+
"FormatQcow",
171+
"FormatRar",
172+
"FormatRar5",
173+
"FormatRpm",
174+
"FormatSevenZip",
175+
"FormatSplit",
176+
"FormatSquashFS",
177+
"FormatSwf",
178+
"FormatSwfc",
179+
"FormatTE",
180+
"FormatTar",
181+
"FormatUEFIc",
182+
"FormatUEFIs",
183+
"FormatUdf",
184+
"FormatVdi",
185+
"FormatVhd",
186+
"FormatVhdx",
187+
"FormatVmdk",
188+
"FormatWim",
189+
"FormatXar",
190+
"FormatXz",
191+
"FormatZ",
192+
"FormatZip",
193+
"OverwriteMode",
194+
"UpdateMode",
195+
"__version__",
196+
]
18197

19-
if not Path(core.set_lib7zip_path()).exists():
198+
if not pathlib.Path(set_lib7zip_path()).exists():
20199
lib7zip_path = (
21-
distribution(__package__).locate_file(__package__) / core.set_lib7zip_path()
200+
distribution(__package__).locate_file(__package__) / set_lib7zip_path()
22201
)
23202
if lib7zip_path.exists():
24-
core.set_lib7zip_path(str(lib7zip_path))
25-
core.set_large_page_mode()
203+
set_lib7zip_path(str(lib7zip_path))
204+
set_large_page_mode()

0 commit comments

Comments
 (0)