@litert/bencode
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

LiteRT/Bencode

npm version License node GitHub issues GitHub Releases

A bencode decode/encode library based on Node.js.

Requirement

  • TypeScript v3.1.x (or newer)
  • Node.js v8.0.0 (or newer)

Installation

npm i @litert/bencode --save

Usage

Encoding:

import * as libBencode from "@litert/bencode";

const enc = new libBEncode.BencodeEncoder();

const beData = enc.encode({ // Encode data into BEncode.
    "name": "Angus",
    "age": 18,
    "friends": [
        "Edith",
        "Alex"
    ],
    "scores": {
        "math": 87
    },
    "randomBytes": Buffer.from('vsm/GvyGjZqUeuPa7ZP8h9ot8VRCe/6arpboI46EIlg=', 'base64')
});

/**
 * Don't print as a UTF-8 string, because it's binary.
 */
console.log(beData);

Decoding:

import * as libBencode from "@litert/bencode";

const dec = new LibBencode.BencodeDecoder();

const beData = dec.decode('d4:name5:Angus7:friendsld4:name5:Editheee');

console.log(beData); // Output: { name: 'Angus', friends: [ { name: 'Edith' } ] }

License

This library is published under Apache-2.0 license.

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.2.056latest

Version History

VersionDownloads (Last 7 Days)Published
0.2.056
0.1.22
0.1.11
0.1.00

Package Sidebar

Install

npm i @litert/bencode

Weekly Downloads

59

Version

0.2.0

License

Apache-2.0

Unpacked Size

76.4 kB

Total Files

36

Last publish

Collaborators

  • fenying