Skip to content

@technobuddha > library > Binary > Encoding

Function: dataURL()

ts
function dataURL(input: BinaryObject, mimeType: string): string;

Defined in: data-url.ts:18

Convert any binary object into a data URL

Parameters

ParameterTypeDescription
inputBinaryObjectThe binary object
mimeTypestringThe MIME type for the URL

Returns

string

The data URL

Example

typescript
const bytes = new Uint8Array([72, 101, 108, 108, 111]); // "Hello"
dataURL(bytes, 'text/plain');
// url === "data:text/plain;base64,SGVsbG8="