A deno library for encoding and decoding bencoded data

A deno library for encoding and decoding bencoded data

Deno Bencode A deno library for encoding and decoding bencoded data, according to the Unofficial BitTorrentSpecification.

Deno Bencode

A deno library for encoding and decoding bencoded data, according to the Unofficial BitTorrentSpecification.

Usage

import { encode, decode } from "https://deno.land/x/[email protected]/mod.ts"

const encoded = encode({
  str: "deno_bencode",
  num: 1,
  uint8Array: new Uint8Array([1, 2, 3]),
  object: {
    str: "object",
  },
  arr: ["arr", 1],
})
console.log(encoded)
// Uint8Array(86) [
//   100,  51,  58,  97, 114, 114, 108,  51,  58,  97, 114, 114, 105,
//    49, 101, 101,  51,  58, 110, 117, 109, 105,  49, 101,  54,  58,
//   111,  98, 106, 101,  99, 116, 100,  51,  58, 115, 116, 114,  54,
//    58, 111,  98, 106, 101,  99, 116, 101,  51,  58, 115, 116, 114,
//    49,  50,  58, 100, 101, 110, 111,  95,  98, 101, 110,  99, 111,
//   100, 101,  49,  48,  58, 117, 105, 110, 116,  56,  65, 114, 114,
//    97, 121,  51,  58,   1,   2,   3, 101
// ]

console.log(decode(encoded))
// {
//   arr: [ "arr", 1 ],
//   num: 1,
//   object: { str: "object" },
//   str: "deno_bencode",
//   uint8Array: "\x01\x02\x03"
// }

Encode && Decode

type bencodeValue = string | Uint8Array | number | { [key: string]: bencodeValue } | bencodeValue[]

const encode = (data: bencodeValue | bencodeValue[]): Uint8Array

const decode = (payload: ArrayBufferView | ArrayBuffer | string): bencodeValue

About byte string

If byte string is a valid utf-8 string, it will be decoded with TextDecoder. Otherwise, it is returned as Uint8Array.

Download Details:

Author: cj1128

Source Code: https://github.com/cj1128/deno-bencode

deno node nodejs javascript

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

AEM Querybuilder for JavaScript (Browser, Node, Deno)

Helix Querybuilder .AEM Querybuilder for JavaScript (Browser, Node, Deno)

NKeys for JavaScript - Node.js, Browsers, and Deno

A public-key signature system based on Ed25519 for the NATS ecosystem system for JavaScript. The nkeys.js library works in Deno, Node.js, and the browser!

Javascript module for easily generating mazes,compatible with both Deno and Node

A work-in-progress Javascript maze generator module, compatible with both Deno and Node.

Deno Tutorial for Beginners: Deno vs. Node: Better Than NodeJS?

Deno is released, it’s time to find out if it can prove a worthy competition for Node.js. What is Deno? Why Deno can be considered an alternative to Node? The main differences between Deno and Node. Write a simple Deno app.

What is Deno? The Node.JS Killer? The Deno-minator to Node?

What is Deno? The Node.JS Killer? The Deno-minator to Node? Deno is the new hype and will it be better than node.js? Deno is a secure runtime for JavaScript and TypeScript that is based on the V8 JavaScript engine and the Rust programming language that addresses Node’s shortcomings