New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@planetarium/bencodex

Package Overview
Dependencies
Maintainers
6
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@planetarium/bencodex

An alternative take on implementing Bencodex in TypeScript/JavaScript

  • 0.2.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
6
Created
Source

Bencodex.js

deno.land/x/bencodex status npm status CI status Coverage status

This library is an alternative take on implementing Bencodex in JavaScript.

It focused to address the following problems from the existing JavaScript implementation(s):

Distributed under LGPL 2.1 or later.

Getting started

See also the complete API references as well.

Deno

It's available on deno.land/x/bencodex:

import { decode, encode } from "https://deno.land/x/bencodex/mod.ts";

const value = new Map([
  ["foo", true],
  ["bar", null],
  ["baz", new Uint8Array([0x73, 0x70, 0x61, 0x6d])],
  [
    new Uint8Array([0x68, 0x65, 0x6c, 0x6c, 0x6f]),
    [
      123456n,
      "Unicode string",
      false,
    ],
  ],
]);
const encoded = encode(value);
const decoded = decode(encoded);

Node.js

Add @planetarium/bencodex to your dependencies using your favorite package manager:

npm install @planetarium/bencodex

The API usage is equivalent to the example above for Deno, except that you need to import things from "@planetarium/bencodex" instead of the deno.land/x/ URL:

import { decode, encode } from "@planetarium/bencodex";

Types

BencodexTypeScript (Value)
Nullnull
Booleanboolean
Integerbigint (not number)
BinaryUint8Array
Textstring
ListValue[]
DictionaryDictionary

Benchmarks

$ deno bench
cpu: 12th Gen Intel(R) Core(TM) i5-1235U
runtime: deno 1.30.3 (x86_64-unknown-linux-gnu)

file:///home/dahlia/src/planetarium/bencodex.js/bench/comparison.bench.ts
benchmark                        time (avg)             (min … max)       p75       p99      p995
------------------------------------------------------------------- -----------------------------
encoding (bencodex.js)        28.96 µs/iter   (17.24 µs … 10.43 ms)  22.25 µs  117.5 µs 221.98 µs
encoding (disjukr/bencodex)   66.01 µs/iter    (39.36 µs … 4.38 ms)  55.58 µs  215.2 µs 313.14 µs

summary
  encoding (bencodex.js)
   2.28x faster than encoding (disjukr/bencodex)

decoding (bencodex.js)         7.73 µs/iter    (6.35 µs … 16.97 ms)   6.92 µs  17.39 µs  30.93 µs
decoding (disjukr/bencodex)   45.76 µs/iter     (31.2 µs … 5.08 ms)  46.35 µs 135.29 µs 185.85 µs

summary
  decoding (bencodex.js)
   5.92x faster than decoding (disjukr/bencodex)

You can run the benchmarks by deno bench.

Keywords

FAQs

Package last updated on 06 Mar 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc