rong_buffer

二进制数据处理

本页 API 参考由仓库内的英文文档生成,暂仅提供英文版。

Blob & File

Web-standard Blob and File implementation.

Blob

const blob = new Blob(["Hello ", "World"], { type: "text/plain" });
blob.size;  // 11
blob.type;  // "text/plain"

Methods

// Slice
const part = blob.slice(0, 5, "text/plain");

// Read contents
const text = await blob.text();
const buf = await blob.arrayBuffer();
const bytes = await blob.bytes();        // Uint8Array

File

Extends Blob with filename and modification time.

const file = new File(["content"], "hello.txt", {
  type: "text/plain",
  lastModified: Date.now(),
});

file.name;          // "hello.txt"
file.lastModified;  // timestamp
file.size;          // 7