How to use the Blob function from buffer

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

There is no buffer.Blob in Node.js, but Blob is a built-in object in browsers that represents an immutable, raw data blob.

1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
  buffer.push(...lastString)
  buffer.push(data.slice(0, lastNewline + 1))
  lastString = [data.slice(lastNewline + 1)]
})
const flush = async () => {
  const _buffer = new Blob(buffer)
  buffer = []
  const _stream = preprocessLiveStream({ data: await _buffer.text() }, options.stream)
  const gen = _stream.toGenerator()
  for await (const item of gen()) {
fork icon39
star icon544
watch icon12

2
3
4
5
6
7
8
9
10
11
12


const sizeInKB = str => {
  if (typeof str !== 'string') return 0;
  let blob;
  try {
    blob = new Blob([str]);
  } catch (err) {
    blob = new legacyBlob([str]);
  }
  const sizeInBytes = blob.size;
fork icon0
star icon0
watch icon0

How does buffer.Blob work?

I believe you may have confused the Buffer and Blob types. Buffer is a built-in Node.js class for working with binary data, while Blob is a browser API for representing binary data. For Buffer, it is a class in Node.js that provides methods for working with binary data. The Buffer class is used to represent a fixed-size sequence of bytes and is commonly used in file system operations, network communications, and other low-level operations. It provides methods for creating, reading, and manipulating binary data, including converting to and from strings and other data types. The Blob type in the browser is used to represent a blob of binary data, such as an image or video file. It is commonly used in client-side web applications to send and receive files via HTTP requests, for example when uploading images or videos to a server. The Blob type provides methods for creating, reading, and manipulating binary data, including converting to and from strings and other data types.

Ai Example

1
2
const buffer = Buffer.from("Hello, world!");
const blob = new Blob([buffer], { type: "text/plain" });

This creates a Blob object containing the binary data from the Buffer, with a MIME type of text/plain. The resulting Blob can then be used for various purposes, such as uploading to a server or displaying as an image or video.