new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Bun · all subjects

runtime/binary

8 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Uint8Array.toBase64() signature and usage

Uint8Array.prototype.toBase64() encodes bytes to base64. It is called on a Uint8Array instance and returns a string. Example: const bytes = new Uint8Array([98, 117, 110]); const encoded = bytes.toBase64(); returns "YnVu".

Uint8Array.fromBase64() signature and usage

Uint8Array.fromBase64(encoded) is a static method that decodes a base64 string to a Uint8Array. Example: const decoded = Uint8Array.fromBase64("YnVu"); returns Uint8Array(3) [ 98, 117, 110 ].

Preferred base64 APIs in Bun

Bun recommends using Uint8Array.prototype.toBase64() and Uint8Array.fromBase64() for base64 encoding and decoding instead of the older btoa() and atob() globals. These newer APIs work directly with bytes and are a better fit for binary data.

Base64 encoding strings with TextEncoder

To base64 encode a string in Bun, convert it to UTF-8 bytes using TextEncoder, then call toBase64(). Example: const bytes = new TextEncoder().encode("hello world"); const encoded = bytes.toBase64(); returns "aGVsbG8gd29ybGQ=".

Base64 decoding strings with TextDecoder

To base64 decode a string in Bun, use Uint8Array.fromBase64() to get bytes, then decode UTF-8 with TextDecoder. Example: const decoded = Uint8Array.fromBase64(encoded); const text = new TextDecoder().decode(decoded); returns "hello world".

Buffer.toBase64() for Node.js compatibility

Node.js Buffer extends Uint8Array, so buffers can be encoded with toBase64(). Example: const encoded = Buffer.from("hello world").toBase64(); returns "aGVsbG8gd29ybGQ=".

Buffer.from(encoded, 'base64') decoding

Buffer.from(encoded, "base64") provides Node.js-compatible base64 decoding and returns a Buffer, which is also a Uint8Array. The result can be converted to string with toString("utf8").

btoa() and atob() compatibility in Bun

The older btoa() and atob() APIs are still available in Bun for compatibility. btoa() encodes a binary string to base64 and atob() decodes base64 to a binary string. These should be avoided in new code, especially when handling arbitrary binary data or non-ASCII text.

Give your agent this brain