Blob & File

GitHubEdit on GitHub
Packages@univerjs/core
CORE

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

Overview

@univerjs/core

MethodDescription
copyBlobReturns a copy of this blob
extend-
get-
getAsReturn the data inside this object as a blob converted to the specified content type
getBytesGets the data stored in this blob
getContentTypeGets the content type of the data stored in this blob
getDataAsString-
onBeforeRedo-
onBeforeUndo-
onReady-
onRedo-
onRendered-
onStarting-
onSteady-
onUndo-
setBytesSets the data stored in this blob
setContentTypeSets the content type of the data stored in this blob
setDataFromString-

APIs

Getters & Queries

get

Signature

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

getAs(contentType: string): FBlob

Parameters

  • contentType stringNo description

Returns

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

Examples

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

getBytes(): Promise<Uint8Array>

Returns

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

Examples

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

getContentType(): string | undefined

Returns

  • string — the content type

Examples

const blob = univerAPI.newBlob();
const contentType = blob.getContentType();
console.log(contentType);
Source: @univerjs/core

getDataAsString

Signature

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

setBytes(bytes: Uint8Array): FBlob

Parameters

  • bytes Uint8Array<ArrayBufferLike>No description

Returns

  • FBlob — the blob object

Examples

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

setContentType(contentType: string): FBlob

Parameters

  • contentType stringNo description

Returns

  • FBlob — the blob object

Examples

const blob = univerAPI.newBlob();
blob.setContentType('text/plain');
Source: @univerjs/core

setDataFromString

Signature

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

Parameters

  • data stringNo description
  • contentType string (optional)No description

Returns

  • FBlob — See signature above.
Source: @univerjs/core

Actions & Operations

copyBlob

Returns a copy of this blob.

Signature

copyBlob(): FBlob

Returns

  • FBlob — a new blob by copying the current blob

Examples

const blob = univerAPI.newBlob();
const newBlob = blob.copyBlob();
console.log(newBlob);
Source: @univerjs/core

Events

onBeforeRedo

Deprecated — use univerAPI.addEvent(univerAPI.Event.BeforeRedo, (event) =&gt; &#123;&#125;) as instead

Signature

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

Parameters

  • callback (action: IUndoRedoItem) => voidNo description

Returns

  • IDisposable — See signature above.
Source: @univerjs/core

onBeforeUndo

Deprecated — use univerAPI.addEvent(univerAPI.Event.BeforeUndo, (event) =&gt; &#123;&#125;) as instead

Signature

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

Parameters

  • callback (action: IUndoRedoItem) => voidNo description

Returns

  • IDisposable — See signature above.
Source: @univerjs/core

onReady

Deprecated — use univerAPI.addEvent(univerAPI.Event.LifeCycleChanged, (&#123; stage &#125;) =&gt; &#123;&#125;) as instead

Signature

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

Parameters

  • callback () => voidNo description

Returns

  • IDisposable — See signature above.
Source: @univerjs/core

onRedo

Deprecated — use univerAPI.addEvent(univerAPI.Event.Redo, (event) =&gt; &#123;&#125;) as instead

Signature

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

Parameters

  • callback (action: IUndoRedoItem) => voidNo description

Returns

  • IDisposable — See signature above.
Source: @univerjs/core

onRendered

Deprecated — use univerAPI.addEvent(univerAPI.Event.LifeCycleChanged, (&#123; stage &#125;) =&gt; &#123;&#125;) as instead

Signature

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

Parameters

  • callback () => voidNo description

Returns

  • IDisposable — See signature above.
Source: @univerjs/core

onStarting

Deprecated — use univerAPI.addEvent(univerAPI.Event.LifeCycleChanged, (&#123; stage &#125;) =&gt; &#123;&#125;) as instead

Signature

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

Parameters

  • callback () => voidNo description

Returns

  • IDisposable — See signature above.
Source: @univerjs/core

onSteady

Deprecated — use univerAPI.addEvent(univerAPI.Event.LifeCycleChanged, (&#123; stage &#125;) =&gt; &#123;&#125;) as instead

Signature

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

Parameters

  • callback () => voidNo description

Returns

  • IDisposable — See signature above.
Source: @univerjs/core

onUndo

Deprecated — use univerAPI.addEvent(univerAPI.Event.Undo, (event) =&gt; &#123;&#125;) as instead

Signature

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

Parameters

  • callback (action: IUndoRedoItem) => voidNo description

Returns

  • IDisposable — See signature above.
Source: @univerjs/core

Miscellaneous

extend

Signature

static extend(source: any): void

Parameters

  • source anyNo description
Source: @univerjs/core