https://github.com/aaravmalani/bencoder
A parser for BitTorrent .torrent files
https://github.com/aaravmalani/bencoder
bencode bencode-parser bencoder bencoding bittorent c cmake collaborate library torrent
Last synced: about 1 month ago
JSON representation
A parser for BitTorrent .torrent files
- Host: GitHub
- URL: https://github.com/aaravmalani/bencoder
- Owner: AaravMalani
- License: mit
- Created: 2023-05-22T16:03:11.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2023-05-22T16:25:29.000Z (about 2 years ago)
- Last Synced: 2025-02-15T17:46:58.621Z (3 months ago)
- Topics: bencode, bencode-parser, bencoder, bencoding, bittorent, c, cmake, collaborate, library, torrent
- Language: C
- Homepage:
- Size: 9.77 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# bencoder: A parser for BitTorrent .torrent files
## Installation
- Go to the [latest release](https://github.com/AaravMalani/bencoder/releases/latest)
- Download the RPM file for Red-Hat based Linux Systems, DEB file for Debian based systems or the DLL or LIB file for Windows
```sh
# Ubuntu/Debian
sudo dpkg -i .deb# RedHat Based Linux
sudo rpm -i .rpm
```
For Windows, you have to link it into the Visual Studio Project using the Linker menu in the Properties of the Project.
Then download the [`bencoder.h`](https://raw.githubusercontent.com/AaravMalani/bencoder/main/include/bencoder.h) file and include that as a header file.## Usage
```c
#includechar* bencodeTypes[4] = {
"INTEGER", // data = long long* (A pointer not a constant value)
"STRING", // data = char*
"LIST", // data = struct BencodeStructure* (contiguous structs not to be confused with array of pointers)
"DICTIONARY" // data = struct BencodeMap* (contiguous structs not to be confused with array of pointers)
};int main(int argc, char **argv)
{
if (argc != 2){
printf("Usage: %s \n", argv[0]);
return 1;
}
// Load file
FILE *f = fopen(argv[1], "r");
if (f == NULL)
{
perror(argv[1]);
return 1;
}
fseek(f, 0, SEEK_END);
size_t fsize = ftell(f);
rewind(f);
char *data = malloc(fsize);
fread(data, fsize, 1, f);
fclose(f);// Parse bencode
struct BencodeStructure* struc = parseBencode(data, fsize);
free(data);
if (!struc) // Error
{
printf("Error parsing file\n");
return 1;
}
printf("Type: %s\n", bencodeTypes[struc->type]);
freeBencode(struc);
}
```