# Cypress Documentation
# Source: https://raw.githubusercontent.com/cypress-io/cypress-documentation/main/docs/api/utilities/buffer.mdx
# Path: docs/api/utilities/buffer.mdx

---
title: 'Cypress.Buffer | Cypress Documentation'
description: Cypress automatically includes a Buffer polyfill for the browser and exposes it as `Cypress.Buffer`.
sidebar_label: Cypress.Buffer
---

<ProductHeading product="app" />

# Cypress.Buffer

Cypress automatically includes a [Buffer](https://github.com/feross/buffer)
polyfill for the browser and exposes it as `Cypress.Buffer`.

Use `Cypress.Buffer` to manipulate binary data, similar to the
[nodejs Buffer class](https://nodejs.org/api/buffer.html). Instances are
returned by [`cy.readFile()`](/api/commands/readfile) and
[`cy.fixture()`](/api/commands/fixture), and it is used with
[`.selectFile()`](/api/commands/selectfile).

## Syntax

```javascript
Cypress.Buffer.method()
```

### Usage

<Icon name="check-circle" color="green" /> **Correct Usage**

```javascript
Cypress.Buffer.method()
```

<Icon name="exclamation-triangle" color="red" /> **Incorrect Usage**

```javascript
cy.Buffer.method() // Errors, cannot be chained off 'cy'
```

## Examples

### Loading binary data read from disk

```javascript
cy.readFile('images/logo.png', null).then((file) => {
  expect(Cypress.Buffer.isBuffer(file)).to.be.true
  // Do something with `file` Buffer here
})
```

### Using dynamic file contents with `.selectFile()`

```javascript
const files = []

for (var i = 1; i <= 10; i++) {
  files.push(Cypress.Buffer.from(`Contents of file #${i}`))
}

// Attach 10 files, of the form "Contents of file #1", "Contents of file #2", etc.
cy.get('input[type=file]').selectFile(files)
```

## History

| Version                            | Changes                 |
| ---------------------------------- | ----------------------- |
| [9.3.0](/app/references/changelog) | Added `Cypress.Buffer`. |

## See also

- [Bundled Libraries](/app/references/bundled-libraries)