Module basic module

module base32

base32 encoding and decoding module

base32module is a module for base32 encoding and decoding. Base32 is an algorithm used to encode binary data into ASCII strings and is used to transmit binary data in network protocols such as email and DNS.

This module provides two methods: encodeand decode. The encodemethod is used to encode binary data into a Base32 string, and decodethe method is used to decode a Base32 string into binary data. Here is an example of usage:

1 2 3 4 5
const base32 = require('base32'); const data = new Uint8Array([0x4e, 0x4f, 0x44, 0x45]); // 'NODE' const encoded = base32.encode(data); // 'KRUGKIDROV======' const decoded = base32.decode(encoded); // [0x4e, 0x4f, 0x44, 0x45] console.log(encoded, decoded); // KRUGKIDROV====== [78, 79, 68, 69]

As you can see, encodethe method encodes the binary data to KRUGKIDROV======, while decodethe method decodes it to [0x4e, 0x4f, 0x44, 0x45].

It should be noted that the length of the resulting string encoded by Base32 is about 8/5 times the length of the original binary data, so it is not suitable for encoding large amounts of data. If you need to encode a large amount of data, it is recommended to use Base64 encoding.

static function


Encode data in base32 format

static String base32.encode(Buffer data);

Call parameters:

  • data:Buffer, the data to be encoded

Return results:

  • String, returns the encoded string


Decode string into binary data in base32 mode

static Buffer base32.decode(String data);

Call parameters:

  • data: String, the string to be decoded

Return results:

  • Buffer, returns the decoded binary data