UNPKG

@helia/bitswap

Version:

JavaScript implementation of the Bitswap data exchange protocol used by Helia

19 lines (13 loc) 375 B
import { encode, encodingLength } from 'uint8-varint' function varintEncoder (buf: number[]): Uint8Array { let out = new Uint8Array(buf.reduce((acc, curr) => { return acc + encodingLength(curr) }, 0)) let offset = 0 for (const num of buf) { out = encode(num, out, offset) offset += encodingLength(num) } return out } export default varintEncoder