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

binary/blob

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

Blob constructor accepts Buffer in array

A Blob can be constructed by passing an array containing chunks. Each chunk can be a string, binary data structure (including Buffer), or another Blob. Example: const buf = Buffer.from("hello"); const blob = new Blob([buf]);

Convert Buffer to Blob example

const buf = Buffer.from("hello"); const blob = new Blob([buf]);

Convert Buffer to ReadableStream using ReadableStream constructor

To convert a Buffer to a ReadableStream using the constructor, create a new ReadableStream with a start function that enqueues the entire buffer and then closes the controller. Example: const buf = Buffer.from("hello world"); const stream = new ReadableStream({ start(controller) { controller.enqueue(buf); controller.close(); } });

Convert Buffer to ReadableStream using Blob.stream()

To convert a Buffer to a ReadableStream with better streaming of smaller chunks, create a Blob instance from the Buffer and call .stream() on it. Example: const buf = Buffer.from("hello world"); const blob = new Blob([buf]); const stream = blob.stream();

Set chunk size for Blob.stream()

When converting a Buffer to a ReadableStream via Blob.stream(), pass a number argument to set the chunk size in bytes. Example: const buf = Buffer.from("hello world"); const blob = new Blob([buf]); const stream = blob.stream(1024);

Naive approach to Buffer to ReadableStream conversion undesirable for large buffers

Using the ReadableStream constructor to enqueue an entire large buffer as a single chunk is undesirable because it does not stream the data in smaller chunks.

Blob constructor accepts Uint8Array chunks

A Blob can be constructed from an array of chunks, where each chunk can be a string, a binary data structure including Uint8Array, or another Blob. The constructor takes an array as its first argument: new Blob([chunk1, chunk2, ...]).

Convert Uint8Array to Blob example

const arr = new Uint8Array([0x68, 0x65, 0x6c, 0x6c, 0x6f]); const blob = new Blob([arr]); console.log(await blob.text()); // => "hello" This example shows creating a Uint8Array with byte values that represent ASCII text, wrapping it in a Blob, and reading the text content back out.

Blob.stream() with custom chunk size

The Blob.stream() method accepts an optional number parameter to set the chunk size in bytes. For example, blob.stream(1024) sets a chunk size of 1024 bytes.

Give your agent this brain