# Blob

Blob utilities for WordPress.

## Installation

Install the module

```bash
npm install @wordpress/blob --save
```

## API

<!-- START TOKEN(Autogenerated API docs) -->

### createBlobURL

Create a blob URL from a file.

_Parameters_

-   _file_ `File`: The file to create a blob URL for.

_Returns_

-   `string`: The blob URL.

### downloadBlob

Downloads a file, e.g., a text or readable stream, in the browser. Appropriate for downloading smaller file sizes, e.g., \< 5 MB.

Example usage:

```js
const fileContent = JSON.stringify(
	{
		title: 'My Post',
	},
	null,
	2
);
const filename = 'file.json';

downloadBlob( filename, fileContent, 'application/json' );
```

_Parameters_

-   _filename_ `string`: File name.
-   _content_ `BlobPart`: File content (BufferSource | Blob | string).
-   _contentType_ `string`: (Optional) File mime type. Default is `''`.

### getBlobByURL

Retrieve a file based on a blob URL. The file must have been created by `createBlobURL` and not removed by `revokeBlobURL`, otherwise it will return `undefined`.

_Parameters_

-   _url_ `string`: The blob URL.

_Returns_

-   `File | undefined`: The file for the blob URL.

### getBlobTypeByURL

Retrieve a blob type based on URL. The file must have been created by `createBlobURL` and not removed by `revokeBlobURL`, otherwise it will return `undefined`.

_Parameters_

-   _url_ `string`: The blob URL.

_Returns_

-   `string | undefined`: The blob type.

### isBlobURL

Check whether a url is a blob url.

_Parameters_

-   _url_ `string | undefined`: The URL.

_Returns_

-   `boolean`: Is the url a blob url?

### revokeBlobURL

Remove the resource and file cache from memory.

_Parameters_

-   _url_ `string`: The blob URL.

<!-- END TOKEN(Autogenerated API docs) -->

## Contributing to this package

This is an individual package that's part of the Gutenberg project. The project is organized as a monorepo. It's made up of multiple self-contained software packages, each with a specific purpose. The packages in this monorepo are published to [npm](https://www.npmjs.com/) and used by [WordPress](https://make.wordpress.org/core/) as well as other software projects.

To find out more about contributing to this package or Gutenberg as a whole, please read the project's main [contributor guide](https://github.com/WordPress/gutenberg/tree/HEAD/CONTRIBUTING.md).

<br /><br /><p align="center"><img src="https://s.w.org/style/images/codeispoetry.png?1" alt="Code is Poetry." /></p>
