Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xtyxtyx/bencode
This library provides classes to encode/decode bencoded bytes. Mainly used to implement bittorrent related functions.
https://github.com/xtyxtyx/bencode
bencode decode encode torrent
Last synced: about 2 months ago
JSON representation
This library provides classes to encode/decode bencoded bytes. Mainly used to implement bittorrent related functions.
- Host: GitHub
- URL: https://github.com/xtyxtyx/bencode
- Owner: xtyxtyx
- License: mit
- Created: 2019-07-22T15:03:08.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-07-22T15:14:15.000Z (over 5 years ago)
- Last Synced: 2023-08-20T23:24:35.741Z (over 1 year ago)
- Topics: bencode, decode, encode, torrent
- Language: Dart
- Homepage: https://pub.dev/packages/torrent_bencode
- Size: 29.3 KB
- Stars: 6
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
This library provides classes to encode/decode bencoded bytes.
Mainly used to implement bittorrent related functions.## Features
- Decode/encode bencoded bytes.
## Usage
Example:
```dart
import 'dart:typed_data';
import 'package:bencode/bencode.dart';main() async {
var decoded = bDecoder.convertString('d5:hello5:worlde');
// or final decoded = bDecoder.convert('d5:hello5:worlde'.runes.toString());
print(decoded);
// Output: {hello: world}
print(decoded is Map);
// Output: truedecoded = bDecoder.convertString('i123e');
print(decoded);
// Output: 123
print(decoded is int);
// Output: truedecoded = bDecoder.convertString('li123ei123ee');
print(decoded);
// Output: [123, 123]
print(decoded is List);
// Output: truedecoded = bDecoder.convertString('11:hello world');
print(decoded);
// bencoded strings are converted to bytes by default.
// Output: [104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100]
print(String.fromCharCodes(decoded));
// Output: hello world
print(decoded is List);
// Output: truevar encoded = bEncoder.convert({'hello': 'world'});
print(encoded);
// Output: [100, 53, 58, 104, 101, 108, 108, 111, 53, 58, 119, 111, 114, 108, 100, 101]
print(String.fromCharCodes(encoded));
// Output: d5:hello5:worldeencoded = bEncoder.convert(123);
print(String.fromCharCodes(encoded));
// Output: i123eencoded = bEncoder.convert([123, 456]);
print(String.fromCharCodes(encoded));
// Output: li123ei456eeencoded = bEncoder.convert(Uint8List.fromList([123, 123]));
print(encoded);
// Output: [50, 58, 123, 123]
print(String.fromCharCodes(encoded));
// Output: 2:{{
}```
Decode bittorrent files:
```dart
import 'dart:io';
import 'package:bencode/bencode.dart';main() async {
final data = File('test/multi.torrent').readAsBytesSync();
final decoded = bDecoder.convert(data);
print(decoded.keys);
// Output: (announce, announce-list, created by, creation date, encoding, info)
}
```## Tests
Run tests:
```
pub run test
```## Features and bugs
Please file feature requests and bugs at the [issue tracker][tracker].
[tracker]: http://github.com/xtyxtyx/bencode/issues