1- # Pyben v0.2.1
1+ # Pyben v0.2.3
22
33Small library for encoding/decoding bencode data.
44Pyben Enables fast and easy encoding and decoding of bencoded data.
@@ -8,10 +8,13 @@ Pyben Enables fast and easy encoding and decoding of bencoded data.
88![ GitHub repo size] ( https://img.shields.io/github/repo-size/alexpdev/pyben )
99![ GitHub contributors] ( https://img.shields.io/github/license/alexpdev/pyben )
1010![ GitHub stars] ( https://img.shields.io/badge/rating-99-green )
11+ [ ![ Codacy Badge] ( https://app.codacy.com/project/badge/Grade/af86338dcf0a4a899228df470d20e894 )] ( https://www.codacy.com/gh/alexpdev/pyben/dashboard?utm_source=github.com& ; utm_medium=referral& ; utm_content=alexpdev/pyben& ; utm_campaign=Badge_Grade )
12+ [ ![ Codacy Badge] ( https://app.codacy.com/project/badge/Coverage/af86338dcf0a4a899228df470d20e894 )] ( https://www.codacy.com/gh/alexpdev/pyben/dashboard?utm_source=github.com&utm_medium=referral&utm_content=alexpdev/pyben&utm_campaign=Badge_Coverage )
13+ [ ![ codecov] ( https://codecov.io/gh/alexpdev/pyben/branch/master/graph/badge.svg?token=N6TCUUQ6CJ )] ( https://codecov.io/gh/alexpdev/pyben )
1114
1215## Prerequisites
1316
14- * Python3 installed and enabled
17+ Python v3.6+
1518
1619## Installing PyBen
1720
@@ -27,30 +30,43 @@ Using git:
2730
2831## Using PyBen
2932
30- The API is intentionally designed to mimic Python's json module .
33+ The API is intentionally designed to mimic Python's json and pickle modules .
3134
32- >>> fd = "path/to/file"
35+ >>> import os
36+ >>> import pyben
37+ >>> file_path = "path/to/encoded.file"
3338 >>> data = {"item1": ["item2", 3, [4], {5: "item6"}]}
3439 >>> encoded = pyben.dumps(data)
3540 >>> encoded
36- ... b'd5:item1l5:item2i3eli4eedi5e5:item6eee'
41+ ... b'd5:item1l5:item2i3eli4eedi5e5:item6eee'
3742 >>> decoded = pyben.loads(encoded)
38- ... {'item1': ['item2', 3, [4], {5: 'item6'}]}
43+ >>> decoded
44+ ... {'item1': ['item2', 3, [4], {5: 'item6'}]}
45+ >>> decoded == data
46+ ... True
3947
4048One key difference is that the 'load' and 'dump' methods accept as arguments,
4149string paths or path objects as well as open iobuffer.
4250
4351For Example this:
4452
45- >> with open("encoded.file", "wb") as fd:
46- ... pyben.dump(data, fd)
47- >> with open("encoded.file", "rb") as fd:
48- ... decoded = pyben.load(fd)
53+ >>> with open(file_path, "wb") as fd:
54+ >>> pyben.dump(decoded, fd)
55+ >>> os.path.exists(file_path)
56+ ... True
57+ >>> with open(file_path, "rb") as fd:
58+ >>> decoded_file = pyben.load(fd)
59+ >>> decoded_file == decoded == data
60+ ... True
4961
5062is the same as doing following.
5163
52- >>> pyben.dump(data, "encoded.file")
53- >>> decoded = pyben.load("encoded.file")
64+ >>> pyben.dump(data, file_path)
65+ >>> os.path.exists(file_path)
66+ ... True
67+ >>> decoded_file = pyben.load(file_path)
68+ >>> decoded_file == decoded == data
69+ ... True
5470
5571The full API includes many other functions and classes as well.
5672See docs for more full API.
0 commit comments