Skip to content

JavaScript solution for encoding and decoding the Bencoding format

License

Notifications You must be signed in to change notification settings

benjreinhart/bencode-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bencode-js

Zero dependency JavaScript solution for implementing the encoding and decoding of the Bencode format. Works in both browser and commonjs environments.

Install

npm install bencode-js

For the browser, simply copy either the compressed or uncompressed file into your app and include it on your web page.

Usage

CommonJS environments:

Bencode = require('bencode-js')
Bencode.decode(...)
Bencode.encode(...)

In the browser the object is available globally as window.Bencode.

Bencode#encode(object)

object is either a String, Number, Array, or Object.

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

Bencode#decode(string)

string is a Bencoded string.

Bencode.decode("d3:key5:valuee") // => { key: "value" }

About

JavaScript solution for encoding and decoding the Bencoding format

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published