Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

std/encoding/varint.ts>encode

Deno standard library
Go to Latest
The Standard Library has been moved to JSR. See the blog post for details.
function encode
import { encode } from "https://deno.land/std@0.220.1/encoding/varint.ts";

Takes unsigned number num and converts it into a VarInt encoded Uint8Array, returning a tuple consisting of a Uint8Array slice of the encoded VarInt, and an offset where the VarInt encoded bytes end within the Uint8Array.

If buf is not given then a Uint8Array will be created. offset defaults to 0.

If passed buf then that will be written into, starting at offset. The resulting returned Uint8Array will be a slice of buf. The resulting returned number is effectively offset + bytesWritten.

Parameters

num: bigint | number
optional
buf: Uint8Array = [UNSUPPORTED]
optional
offset = [UNSUPPORTED]

Returns

[Uint8Array, number]