Skip to content

A Dart library for implementing the encoding and decoding of the Bencode format.

License

Notifications You must be signed in to change notification settings

eclipseglory/bencode_dart

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A Dart library for implementing the encoding and decoding of the Bencode format.

All codes come from bencode.js, include example and test codes , I just transfer them to Dart code.

Install

In your flutter or dart project add the dependency:

dependencies:
  bencode_dart: ^1.0.1

Usage

A simple usage example:

Encode

Input parameter can be a String, Number, List, or Map. It will return a encoding bytes list ( Uint8List ).

import 'package:bencode_dart/bencode_dart.dart' as Bencode;

main() {
  Bencode.encode("string")         // => "6:string"
  Bencode.encode(123)              // => "i123e"
  Bencode.encode(["str", 123])     // => "l3:stri123ee"
  Bencode.encode({ "key": "value" }) // => "d3:key5:valuee"
}

Decode

Input should be bytes list or String.

import 'package:bencode_dart/bencode_dart.dart' as Bencode;

main() {
  var map = Bencode.decode(Uint8List.fromList('d3:key5:valuee'.codeUnits); // => { key: "value" } , the string value is bytes array

  print(map);

Features and bugs

Please file feature requests and bugs at the issue tracker.

About

A Dart library for implementing the encoding and decoding of the Bencode format.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages