@longmo-utils/browser / arrayBufferToBlob
Function: arrayBufferToBlob()
ts
function arrayBufferToBlob(arrayBuffer, options?): Blob;将 ArrayBuffer 转换为 Blob
Parameters
| Parameter | Type | Description |
|---|---|---|
arrayBuffer | ArrayBuffer | 要转换的 ArrayBuffer 对象 |
options? | BlobPropertyBag | Blob 配置选项 |
Returns
Blob
返回 Blob 对象
Examples
typescript
const text = 'hello world';
const arrayBuffer = new TextEncoder().encode(text);
const blob = arrayBufferToBlob(arrayBuffer);
console.log(blob.type); // ''
console.log(blob.size); // 11typescript
const arrayBuffer = new Uint8Array([255, 216, 255, 224]);
const jpegBlob = arrayBufferToBlob(arrayBuffer, { type: 'image/jpeg' });
console.log(jpegBlob.type); // 'image/jpeg'typescript
const data = { name: 'test' };
const jsonStr = JSON.stringify(data);
const arrayBuffer = new TextEncoder().encode(jsonStr);
const blob = arrayBufferToBlob(arrayBuffer, { type: 'application/json' });
// 保存或上传 blob...