Skip to main content
Module

x/bencodex/mod.ts

An alternative take on implementing Bencodex in TypeScript/JavaScript
Latest
import * as bencodex from "https://deno.land/x/bencodex@0.2.2/mod.ts";

This façade module exports the public API of this package.

Examples

Encoding a Bencodex list and decoding it back

const encoded = encode(new Map([["foo", 123n]]));
const decoded = decode(encoded);

Classes

A Dictionary implementation that complies with the Bencodex specification. Unlike Map, this implementation allows only keys of type Key and values of type Value, and in particular, it actually compares Uint8Array keys by their contents instead of their references.

An exception that is thrown when an error occurs while decoding a Bencodex.

A view of a RecordValue that implements Dictionary. It is a handy way to construct a Dictionary using JavaScript's object literal syntax.

Functions

Checks if the given Bencodex dictionaries have the same keys and the same associated values. In other words, this function checks if the given dictionaries are encoded in the same Bencodex data.

Checks if the given keys have the same type and the same contents. In other words, this function checks if the given keys are encoded in the same Bencodex data.

Checks if the given Bencodex values have the same type and the same contents. In other words, this function checks if the given values are encoded in the same Bencodex data.

Decodes a Bencodex value from the given buffer.

Decodes a Bencodex value from the given buffer.

Encodes a Bencodex value and returns the encoded bytes.

Encodes a value into the given buffer.

Estimates the byte size of the given value in Bencodex.

Checks if the given value is a Bencodex dictionary.

Checks if the given value can be used as a key in a Bencodex dictionary.

A type guard predicate that checks if the given value is a RecordValue.

Interfaces

Options for decoding a Bencodex value.

Represents a Bencodex dictionary. It basically behaves like a read-only Map<Key, Value>, but it is not necessarily a Map instance.

Options for encode function.

Options for encodeInto and encodeKeyInto functions.

A record object that represents a Bencodex dictionary.

Type Aliases

Represents an error that can occur while decoding a Bencodex value.

Represents the end-state of decoding.

Represents a value which can be used as a key in a Bencodex dictionary. It is either a string ("text" in Bencodex) or a Unit8Array instance ("binary" in Bencodex).

Represents a value which can be encoded in Bencodex. Each data type in Bencodex has its corresponding type in JavaScript: