bencode_dart 1.0.2 bencode_dart: ^1.0.2 copied to clipboard
A Dart library for implementing the encoding and decoding of the Bencode format.
example/bencode_dart_example.dart
import 'dart:typed_data';
import 'package:bencode_dart/bencode_dart.dart' as bencode;
void main() {
print(String.fromCharCodes(bencode.encode('string'))); // => "6:string"
print(String.fromCharCodes(bencode.encode(123))); // => "i123e"
print(
String.fromCharCodes(bencode.encode(['str', 123]))); // => "l3:stri123ee"
print(String.fromCharCodes(
bencode.encode({'key': 'value'}))); // => "d3:key5:valuee"
var map = bencode.decode(Uint8List.fromList('d3:key5:valuee'.codeUnits),
stringEncoding:
'utf-8'); // => { key: "value" } , the string value is bytes array
print(map);
// Special character
var ccc = bencode.encode({'δΈζ': 'ddd'});
var m1 = bencode.decode(ccc);
print(m1);
}