# Blob & File

> Language fallback: requested `zh-CN`; content is `en-US`.

- Human documentation: [https://docs.univer.ai/zh-CN/reference/facade/utils](https://docs.univer.ai/zh-CN/reference/facade/utils)

- Agent Markdown: [https://docs.univer.ai/zh-CN/reference/facade/utils.md](https://docs.univer.ai/zh-CN/reference/facade/utils.md)

- Requested language: `zh-CN`

- Content language: `en-US`

- Documentation version: `1.0.0-rc.0`

- Source: [facade/utils.mdx](https://github.com/dream-num/documentation/blob/dev/content/reference/facade/utils.mdx)

---

| Packages | `@univerjs/core` |
| -------- | ---------------- |

> This class should not be instantiated directly. Use factory methods on `univerAPI` instead.

## Overview

### @univerjs/core

| Method                                    | Description                                                                          |
| ----------------------------------------- | ------------------------------------------------------------------------------------ |
| [`copyBlob`](#copyblob)                   | Returns a copy of this blob                                                          |
| [`extend`](#extend)                       | -                                                                                    |
| [`get`](#get)                             | -                                                                                    |
| [`getAs`](#getas)                         | Return the data inside this object as a blob converted to the specified content type |
| [`getBytes`](#getbytes)                   | Gets the data stored in this blob                                                    |
| [`getContentType`](#getcontenttype)       | Gets the content type of the data stored in this blob                                |
| [`getDataAsString`](#getdataasstring)     | -                                                                                    |
| [`onBeforeRedo`](#onbeforeredo)           | -                                                                                    |
| [`onBeforeUndo`](#onbeforeundo)           | -                                                                                    |
| [`onReady`](#onready)                     | -                                                                                    |
| [`onRedo`](#onredo)                       | -                                                                                    |
| [`onRendered`](#onrendered)               | -                                                                                    |
| [`onStarting`](#onstarting)               | -                                                                                    |
| [`onSteady`](#onsteady)                   | -                                                                                    |
| [`onUndo`](#onundo)                       | -                                                                                    |
| [`rectangle`](#rectangle)                 | Access rectangle helper utilities                                                    |
| [`setBytes`](#setbytes)                   | Sets the data stored in this blob                                                    |
| [`setContentType`](#setcontenttype)       | Sets the content type of the data stored in this blob                                |
| [`setDataFromString`](#setdatafromstring) | -                                                                                    |
| [`tools`](#tools)                         | Access common helper utilities                                                       |

## APIs

### Getters & Queries

### `rectangle`

Access rectangle helper utilities.

**Signature**

```typescript
get rectangle(): typeof Rectangle
```

**Returns**

* `typeof Rectangle` — Rectangle helper utilities exposed through `univerAPI.Util.rectangle`.

Source: 

`@univerjs/core`

### `tools`

Access common helper utilities.

**Signature**

```typescript
get tools(): typeof Tools
```

**Returns**

* `typeof Tools` — Common helper utilities exposed through `univerAPI.Util.tools`.

Source: 

`@univerjs/core`

### `get`

**Signature**

```typescript
static get(): FUtil
```

**Returns**

* `FUtil` — See signature above.

Source: 

`@univerjs/core`

### `getAs`

Return the data inside this object as a blob converted to the specified content type.

**Signature**

```typescript
getAs(contentType: string): FBlob
```

**Parameters**

* `contentType` `string` — *No description*

**Returns**

* `FBlob` — a new blob by converting the current blob to the specified content type

**Examples**

```ts
const blob = univerAPI.newBlob();
const newBlob = blob.getAs('text/plain');
console.log(newBlob);
```

Source: 

`@univerjs/core`

### `getBytes`

Gets the data stored in this blob.

**Signature**

```typescript
getBytes(): Promise<Uint8Array>
```

**Returns**

* `Promise<Uint8Array<ArrayBufferLike>>` — the blob content as a byte array

**Examples**

```ts
const blob = univerAPI.newBlob();
const bytes = await blob.getBytes();
console.log(bytes);
```

Source: 

`@univerjs/core`

### `getContentType`

Gets the content type of the data stored in this blob.

**Signature**

```typescript
getContentType(): string | undefined
```

**Returns**

* `string` — the content type

**Examples**

```ts
const blob = univerAPI.newBlob();
const contentType = blob.getContentType();
console.log(contentType);
```

Source: 

`@univerjs/core`

### `getDataAsString`

**Signature**

```typescript
getDataAsString(charset?: string): Promise<string>
```

**Parameters**

* `charset` `string` *(optional)* — *No description*

**Returns**

* `Promise<string>` — See signature above.

Source: 

`@univerjs/core`

### Setters & Modifiers

### `setBytes`

Sets the data stored in this blob.

**Signature**

```typescript
setBytes(bytes: Uint8Array): FBlob
```

**Parameters**

* `bytes` `Uint8Array<ArrayBufferLike>` — *No description*

**Returns**

* `FBlob` — the blob object

**Examples**

```ts
const blob = univerAPI.newBlob();
const bytes = new Uint8Array(10);
blob.setBytes(bytes);
```

Source: 

`@univerjs/core`

### `setContentType`

Sets the content type of the data stored in this blob.

**Signature**

```typescript
setContentType(contentType: string): FBlob
```

**Parameters**

* `contentType` `string` — *No description*

**Returns**

* `FBlob` — the blob object

**Examples**

```ts
const blob = univerAPI.newBlob();
blob.setContentType('text/plain');
```

Source: 

`@univerjs/core`

### `setDataFromString`

**Signature**

```typescript
setDataFromString(data: string, contentType?: string): FBlob
```

**Parameters**

* `data` `string` — *No description*
* `contentType` `string` *(optional)* — *No description*

**Returns**

* `FBlob` — See signature above.

Source: 

`@univerjs/core`

### Actions & Operations

### `copyBlob`

Returns a copy of this blob.

**Signature**

```typescript
copyBlob(): FBlob
```

**Returns**

* `FBlob` — a new blob by copying the current blob

**Examples**

```ts
const blob = univerAPI.newBlob();
const newBlob = blob.copyBlob();
console.log(newBlob);
```

Source: 

`@univerjs/core`

### Events

### `onBeforeRedo`

> [!WARN]
> Deprecated — use 
> 
> `univerAPI.addEvent(univerAPI.Event.BeforeRedo, (event) =&gt; &#123;&#125;)`
> 
>  as instead

**Signature**

```typescript
onBeforeRedo(callback: (action: IUndoRedoItem) => void): IDisposable
```

**Parameters**

* `callback` `(action: IUndoRedoItem) => void` — *No description*

**Returns**

* `IDisposable` — See signature above.

Source: 

`@univerjs/core`

### `onBeforeUndo`

> [!WARN]
> Deprecated — use 
> 
> `univerAPI.addEvent(univerAPI.Event.BeforeUndo, (event) =&gt; &#123;&#125;)`
> 
>  as instead

**Signature**

```typescript
onBeforeUndo(callback: (action: IUndoRedoItem) => void): IDisposable
```

**Parameters**

* `callback` `(action: IUndoRedoItem) => void` — *No description*

**Returns**

* `IDisposable` — See signature above.

Source: 

`@univerjs/core`

### `onReady`

> [!WARN]
> Deprecated — use 
> 
> `univerAPI.addEvent(univerAPI.Event.LifeCycleChanged, (&#123; stage &#125;) =&gt; &#123;&#125;)`
> 
>  as instead

**Signature**

```typescript
onReady(callback: () => void): IDisposable
```

**Parameters**

* `callback` `() => void` — *No description*

**Returns**

* `IDisposable` — See signature above.

Source: 

`@univerjs/core`

### `onRedo`

> [!WARN]
> Deprecated — use 
> 
> `univerAPI.addEvent(univerAPI.Event.Redo, (event) =&gt; &#123;&#125;)`
> 
>  as instead

**Signature**

```typescript
onRedo(callback: (action: IUndoRedoItem) => void): IDisposable
```

**Parameters**

* `callback` `(action: IUndoRedoItem) => void` — *No description*

**Returns**

* `IDisposable` — See signature above.

Source: 

`@univerjs/core`

### `onRendered`

> [!WARN]
> Deprecated — use 
> 
> `univerAPI.addEvent(univerAPI.Event.LifeCycleChanged, (&#123; stage &#125;) =&gt; &#123;&#125;)`
> 
>  as instead

**Signature**

```typescript
onRendered(callback: () => void): IDisposable
```

**Parameters**

* `callback` `() => void` — *No description*

**Returns**

* `IDisposable` — See signature above.

Source: 

`@univerjs/core`

### `onStarting`

> [!WARN]
> Deprecated — use 
> 
> `univerAPI.addEvent(univerAPI.Event.LifeCycleChanged, (&#123; stage &#125;) =&gt; &#123;&#125;)`
> 
>  as instead

**Signature**

```typescript
onStarting(callback: () => void): IDisposable
```

**Parameters**

* `callback` `() => void` — *No description*

**Returns**

* `IDisposable` — See signature above.

Source: 

`@univerjs/core`

### `onSteady`

> [!WARN]
> Deprecated — use 
> 
> `univerAPI.addEvent(univerAPI.Event.LifeCycleChanged, (&#123; stage &#125;) =&gt; &#123;&#125;)`
> 
>  as instead

**Signature**

```typescript
onSteady(callback: () => void): IDisposable
```

**Parameters**

* `callback` `() => void` — *No description*

**Returns**

* `IDisposable` — See signature above.

Source: 

`@univerjs/core`

### `onUndo`

> [!WARN]
> Deprecated — use 
> 
> `univerAPI.addEvent(univerAPI.Event.Undo, (event) =&gt; &#123;&#125;)`
> 
>  as instead

**Signature**

```typescript
onUndo(callback: (action: IUndoRedoItem) => void): IDisposable
```

**Parameters**

* `callback` `(action: IUndoRedoItem) => void` — *No description*

**Returns**

* `IDisposable` — See signature above.

Source: 

`@univerjs/core`

### Miscellaneous

### `extend`

**Signature**

```typescript
static extend(source: any): void
```

**Parameters**

* `source` `any` — *No description*

Source: 

`@univerjs/core`
