Skip to content
forked from cwyang/bencode

Bittorrent bencode reader and writer module

License

Notifications You must be signed in to change notification settings

gangjeuk/bencode

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bencode Build Status Coverage Status

A robust C library for reading and writing Bittorrent bencode data.

License

Apache license v2.0.

APIs

extern be_node_t *be_decode(const char *inBuf, size_t inBufLen, size_t *readAmount);
extern ssize_t be_encode(const be_node_t *node, char *outBuf, size_t outBufLen);
extern void be_free(be_node_t *node);
extern void be_dump(be_node_t *node);
  • when be_decode() fails, it returns NULL and set errno to:
    • ENOMEM: memory allocation failed
    • EINVAL: invalid bencode data
    • ELOOP: max depth reached (default: 10)
  • be_encode(node, NULL, 0) returns the size of output buffer to be allocated. You can malloc and call be_encode() again with alloc'ed buffer.

Build and Test

$ make && make test
--(snip)--
{ "test": [ "test"]
, "announce": "udp://tracker.openbittorrent.com:80"
, "creation date": 1327049827
, "info": { "length": 20
          , "name": "sample.txt"
          , "piece length": 65536
          , "pieces": "..R....x...d.......1"
          , "private": 1}}
All tests passed!

Thank you for reading :-)

About

Bittorrent bencode reader and writer module

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C 96.9%
  • Makefile 3.1%