How to use the atob function from buffer

Find comprehensive JavaScript buffer.atob code examples handpicked from public code repositorys.

buffer.atob is a built-in Node.js method that decodes a base64-encoded string into a binary string.

100
101
102
103
104
105
106
107
108
109
  return
}

let rtspUrl = params.url;
try {
  rtspUrl = atob(rtspUrl);
} catch (e) {
  console.log(e);
  return;
}
fork icon0
star icon0
watch icon1

How does buffer.atob work?

buffer.atob works by taking a base64-encoded string as its input and converting it into a binary string. In more detail, it: Receives a base64-encoded string as input. Converts each character of the input string into its corresponding ASCII code. Treats each set of three ASCII codes as a 24-bit binary number. Divides each 24-bit number into four 6-bit numbers. Maps each 6-bit number to its corresponding base64 character. Outputs the resulting binary string. Note that buffer.atob is the inverse of buffer.btoa, which performs the opposite conversion from a binary string to a base64-encoded string.

Ai Example

1
2
3
4
5
6
7
8
const buffer = require("buffer");

const encodedString = "SGVsbG8gV29ybGQ=";
const decodedString = buffer.Buffer.from(encodedString, "base64").toString(
  "binary"
);

console.log(decodedString); // Output: "Hello World"

In this example, the base64-encoded string "SGVsbG8gV29ybGQ=" is decoded into the binary string "Hello World". Note that in the Buffer.from() method, the second argument is the encoding of the input string, which is 'base64' in this case. The resulting buffer is then converted to a binary string using the toString() method.