Skip to main content
Module

x/bencodex/mod.ts>encode

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

Encodes a Bencodex value and returns the encoded bytes.

This function allocates a new buffer and returns the encoded bytes. If you want to encode a value into a pre-allocated buffer, use encodeInto instead.

Examples

Encoding a Bencodex list

const encoded = encode([true, "spam"]);
console.log(encoded);
// Uint8Array(10) [ 0x6c, 0x74, 0x75, 0x34, 0x3a, 0x73, 0x70,
//                  0x61, 0x6d, 0x65 ]

Parameters

value: Value

A Bencodex value to encode.

optional
options: EncodingOptions = [UNSUPPORTED]

Encoding options.

Returns

Uint8Array

The encoded bytes.