Skip to content

Commit c91bc53

Browse files
committed
2 parents 35f17bd + 77d1c78 commit c91bc53

File tree

1 file changed

+57
-2
lines changed

1 file changed

+57
-2
lines changed

readme.md

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ Once installed, two command-line tools will be available globally: `cbx2bbf` and
3636
### `cbx2bbf`: Create BBF Files from CBZ/Images
3737

3838
**Usage:**
39-
```cbx2bbf <inputs...> [options] --output <output.bbf>
39+
```
40+
cbx2bbf <inputs...> [options] --output <output.bbf>
4041
```
4142

4243
**Inputs:**
@@ -115,6 +116,60 @@ bbf2cbx <input.bbf> [options] --output <output.cbz_or_dir>
115116
bbf2cbx series.bbf --info
116117
```
117118
119+
## Using `libbbf`
120+
121+
You can also interface libbbf directly from python.
122+
123+
Example 1: Creating a .bbf file
124+
```python
125+
from libbbf import BBFBuilder
126+
import os
127+
128+
# Create a new Bound Book
129+
builder = BBFBuilder("my_comic.bbf")
130+
131+
# Add Metadata
132+
builder.add_metadata("Title", "Solo Leveling")
133+
builder.add_metadata("Author", "Chugong")
134+
135+
# Add Pages (Assets are automatically deduplicated by hash!)
136+
page_files = sorted(os.listdir("./chapter_images"))
137+
for i, filename in enumerate(page_files):
138+
full_path = os.path.join("./chapter_images", filename)
139+
140+
# Flags: 0 = Standard
141+
builder.add_page(full_path, type=1, flags=0)
142+
143+
# Define a Chapter every 20 pages
144+
if i % 20 == 0:
145+
builder.add_section(f"Chapter {i // 20 + 1}", start_page=i)
146+
147+
# Finalize writes the footer and optimized tables
148+
builder.finalize()
149+
print("BBF created successfully.")
150+
```
151+
152+
Example 2: Verifying a .bbf file
153+
```python
154+
import libbbf
155+
import time
156+
157+
reader = libbbf.BBFReader("massive_archive.bbf")
158+
159+
print("Verifying file integrity...")
160+
start = time.time()
161+
162+
# This releases the GIL, so it's thread-safe and incredibly fast
163+
is_valid = reader.verify()
164+
165+
end = time.time()
166+
167+
if is_valid:
168+
print(f"SUCCESS: Integrity verified in {end - start:.4f}s")
169+
else:
170+
print("ERROR: Corruption detected!")
171+
```
172+
118173
## Contributing
119174

120175
Contributions, issues, and feature requests are welcome! For libbbf, free to check the [issues page](https://github.com/ef1500/libbbf/issues) (or create one if it doesn't exist yet).
@@ -123,4 +178,4 @@ Contributions, issues, and feature requests are welcome! For libbbf, free to che
123178

124179
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
125180

126-
---
181+
---

0 commit comments

Comments
 (0)