---
title: Data
description: Raw data representation.
---

Raw data representation.

Raw data representation of strings, files and images.

## Methods

<span id="frombase64string" class="api-anchor"></span>

### fromBase64String(base64String)

Creates data from base64 encoded string.

```typescript
static fromBase64String(base64String: string): Data
```

The supplied string must be base64 encoded otherwise the function will return null.

#### Parameters

**`base64String` `string`**

Base64 encoded string to create data from.

#### Return value

**`Data`**

Data representation of the string.

<span id="frombytes" class="api-anchor"></span>

### fromBytes(bytes)

Creates data from an array of bytes.

```typescript
static fromBytes(bytes: [number]): Data
```

#### Parameters

**`bytes` `[number]`**

Array of bytes to convert to data.

#### Return value

**`Data`**

Data creates from the bytes.

<span id="fromfile" class="api-anchor"></span>

### fromFile(filePath)

Reads data from file path.

```typescript
static fromFile(filePath: string): Data
```

Reads the raw data of the file at the specified file path.

#### Parameters

**`filePath` `string`**

Path of file to read data from.

#### Return value

**`Data`**

Data representation of the file.

<span id="fromjpeg" class="api-anchor"></span>

### fromJPEG(image)

Creates data from JPEG image.

```typescript
static fromJPEG(image: Image): Data
```

#### Parameters

**`image` `Image`**

JPEG image to convert to data.

#### Return value

**`Data`**

Data representation of the image.

<span id="frompng" class="api-anchor"></span>

### fromPNG(image)

Creates data from PNG image.

```typescript
static fromPNG(image: Image): Data
```

#### Parameters

**`image` `Image`**

PNG image to convert to data.

#### Return value

**`Data`**

Data representation of the image.

<span id="fromstring" class="api-anchor"></span>

### fromString(string)

Creates data from string.

```typescript
static fromString(string: string): Data
```

The provided string is assumed to be UTF8 encoded. If the string is not UTF8 encoded, the function will return null.

#### Parameters

**`string` `string`**

String to create data from.

#### Return value

**`Data`**

Data representation of the string.

<span id="-getbytes" class="api-anchor"></span>

### getBytes()

Gets bytes from data.

```typescript
getBytes(): [number]
```

#### Return value

**`[number]`**

Array of bytes.

<span id="-tobase64string" class="api-anchor"></span>

### toBase64String()

Creates a base64 encoded string.

```typescript
toBase64String(): string
```

Creates a base64 encoded string from the data.

#### Return value

**`string`**

Base64 encoded string.

<span id="-torawstring" class="api-anchor"></span>

### toRawString(encoding)

Creates a string from the data.

```typescript
toRawString(encoding?: string): string
```

Specify an IANA character encoding such as "ISO-8859-1" or "UTF-8". When omitted, the encoding is detected automatically. Returns null if the encoding is unknown or the data cannot be decoded.

#### Parameters

**`encoding` `string`**

Optional. IANA character encoding name.

#### Return value

**`string`**

Data converted to string.