{
  "doc": {
    "id": "api/utilities/buffer",
    "title": "Cypress.Buffer | Cypress Documentation",
    "description": "Cypress automatically includes a Buffer polyfill for the browser and exposes it as `Cypress.Buffer`.",
    "section": "api",
    "source_path": "/llm/markdown/api/utilities/buffer.md",
    "version": "3cf5b86b3403f604bdf7f3e35025c3bc3865e02c",
    "updated_at": "2026-05-07T17:44:31.931Z",
    "headings": [
      {
        "id": "api/utilities/buffer#cypress-buffer",
        "text": "Cypress.Buffer",
        "level": 1
      },
      {
        "id": "api/utilities/buffer#syntax",
        "text": "Syntax",
        "level": 2
      },
      {
        "id": "api/utilities/buffer#usage",
        "text": "Usage",
        "level": 3
      },
      {
        "id": "api/utilities/buffer#examples",
        "text": "Examples",
        "level": 2
      },
      {
        "id": "api/utilities/buffer#loading-binary-data-read-from-disk",
        "text": "Loading binary data read from disk",
        "level": 3
      },
      {
        "id": "api/utilities/buffer#using-dynamic-file-contents-with-selectfile",
        "text": "Using dynamic file contents with .selectFile()",
        "level": 3
      },
      {
        "id": "api/utilities/buffer#history",
        "text": "History",
        "level": 2
      },
      {
        "id": "api/utilities/buffer#see-also",
        "text": "See also",
        "level": 2
      }
    ]
  },
  "content": {
    "type": "root",
    "children": [
      {
        "type": "heading",
        "depth": 1,
        "children": [
          {
            "type": "text",
            "value": "Cypress.Buffer"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Cypress automatically includes a "
          },
          {
            "type": "link",
            "title": null,
            "url": "https://github.com/feross/buffer",
            "children": [
              {
                "type": "text",
                "value": "Buffer"
              }
            ]
          },
          {
            "type": "text",
            "value": " polyfill for the browser and exposes it as `Cypress.Buffer`."
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Use `Cypress.Buffer` to manipulate binary data, similar to the "
          },
          {
            "type": "link",
            "title": null,
            "url": "https://nodejs.org/api/buffer.html",
            "children": [
              {
                "type": "text",
                "value": "nodejs Buffer class"
              }
            ]
          },
          {
            "type": "text",
            "value": ". Instances are returned by "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/api/commands/readfile.md",
            "children": [
              {
                "type": "text",
                "value": "`cy.readFile()`"
              }
            ]
          },
          {
            "type": "text",
            "value": " and "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/api/commands/fixture.md",
            "children": [
              {
                "type": "text",
                "value": "`cy.fixture()`"
              }
            ]
          },
          {
            "type": "text",
            "value": ", and it is used with "
          },
          {
            "type": "link",
            "title": null,
            "url": "/llm/markdown/api/commands/selectfile.md",
            "children": [
              {
                "type": "text",
                "value": "`.selectFile()`"
              }
            ]
          },
          {
            "type": "text",
            "value": "."
          }
        ]
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "Syntax"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "Cypress.Buffer.method()"
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Usage"
          }
        ]
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Correct Usage"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "Cypress.Buffer.method()"
      },
      {
        "type": "paragraph",
        "children": [
          {
            "type": "text",
            "value": "Incorrect Usage"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.Buffer.method() // Errors, cannot be chained off 'cy'"
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "Examples"
          }
        ]
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Loading binary data read from disk"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "cy.readFile('images/logo.png', null).then((file) => {  expect(Cypress.Buffer.isBuffer(file)).to.be.true  // Do something with `file` Buffer here})"
      },
      {
        "type": "heading",
        "depth": 3,
        "children": [
          {
            "type": "text",
            "value": "Using dynamic file contents with `.selectFile()`"
          }
        ]
      },
      {
        "type": "code",
        "lang": null,
        "meta": null,
        "value": "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)"
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "History"
          }
        ]
      },
      {
        "type": "table",
        "align": [
          null,
          null
        ],
        "children": [
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Version"
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Changes"
                  }
                ]
              }
            ]
          },
          {
            "type": "tableRow",
            "children": [
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/references/changelog.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "9.3.0"
                      }
                    ]
                  }
                ]
              },
              {
                "type": "tableCell",
                "children": [
                  {
                    "type": "text",
                    "value": "Added `Cypress.Buffer`."
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "type": "heading",
        "depth": 2,
        "children": [
          {
            "type": "text",
            "value": "See also"
          }
        ]
      },
      {
        "type": "list",
        "ordered": false,
        "start": null,
        "spread": false,
        "children": [
          {
            "type": "listItem",
            "spread": false,
            "checked": null,
            "children": [
              {
                "type": "paragraph",
                "children": [
                  {
                    "type": "link",
                    "title": null,
                    "url": "/llm/markdown/app/references/bundled-libraries.md",
                    "children": [
                      {
                        "type": "text",
                        "value": "Bundled Libraries"
                      }
                    ]
                  }
                ]
              }
            ]
          }
        ]
      }
    ]
  },
  "token_estimate": 204
}