/** | |
* Shim for | |
* [`new Blob()`](https://developer.mozilla.org/en-US/docs/Web/API/Blob.Blob) | |
* to support | |
* [older browsers that use the deprecated `BlobBuilder` API](http://caniuse.com/blob). | |
* | |
* Example: | |
* | |
* ```js | |
* var myBlob = blobUtil.createBlob(['hello world'], {type: 'text/plain'}); | |
* ``` | |
* | |
* @param parts - content of the Blob | |
* @param properties - usually `{type: myContentType}`, | |
* you can also pass a string for the content type | |
* @returns Blob | |
*/ | |
export declare function createBlob(parts: Array<any>, properties?: BlobPropertyBag | string): Blob; | |
/** | |
* Shim for | |
* [`URL.createObjectURL()`](https://developer.mozilla.org/en-US/docs/Web/API/URL.createObjectURL) | |
* to support browsers that only have the prefixed | |
* `webkitURL` (e.g. Android <4.4). | |
* | |
* Example: | |
* | |
* ```js | |
* var myUrl = blobUtil.createObjectURL(blob); | |
* ``` | |
* | |
* @param blob | |
* @returns url | |
*/ | |
export declare function createObjectURL(blob: Blob): string; | |
/** | |
* Shim for | |
* [`URL.revokeObjectURL()`](https://developer.mozilla.org/en-US/docs/Web/API/URL.revokeObjectURL) | |
* to support browsers that only have the prefixed | |
* `webkitURL` (e.g. Android <4.4). | |
* | |
* Example: | |
* | |
* ```js | |
* blobUtil.revokeObjectURL(myUrl); | |
* ``` | |
* | |
* @param url | |
*/ | |
export declare function revokeObjectURL(url: string): void; | |
/** | |
* Convert a `Blob` to a binary string. | |
* | |
* Example: | |
* | |
* ```js | |
* blobUtil.blobToBinaryString(blob).then(function (binaryString) { | |
* // success | |
* }).catch(function (err) { | |
* // error | |
* }); | |
* ``` | |
* | |
* @param blob | |
* @returns Promise that resolves with the binary string | |
*/ | |
export declare function blobToBinaryString(blob: Blob): Promise<string>; | |
/** | |
* Convert a base64-encoded string to a `Blob`. | |
* | |
* Example: | |
* | |
* ```js | |
* var blob = blobUtil.base64StringToBlob(base64String); | |
* ``` | |
* @param base64 - base64-encoded string | |
* @param type - the content type (optional) | |
* @returns Blob | |
*/ | |
export declare function base64StringToBlob(base64: string, type?: string): Blob; | |
/** | |
* Convert a binary string to a `Blob`. | |
* | |
* Example: | |
* | |
* ```js | |
* var blob = blobUtil.binaryStringToBlob(binaryString); | |
* ``` | |
* | |
* @param binary - binary string | |
* @param type - the content type (optional) | |
* @returns Blob | |
*/ | |
export declare function binaryStringToBlob(binary: string, type?: string): Blob; | |
/** | |
* Convert a `Blob` to a binary string. | |
* | |
* Example: | |
* | |
* ```js | |
* blobUtil.blobToBase64String(blob).then(function (base64String) { | |
* // success | |
* }).catch(function (err) { | |
* // error | |
* }); | |
* ``` | |
* | |
* @param blob | |
* @returns Promise that resolves with the binary string | |
*/ | |
export declare function blobToBase64String(blob: Blob): Promise<string>; | |
/** | |
* Convert a data URL string | |
* (e.g. `'data:image/png;base64,iVBORw0KG...'`) | |
* to a `Blob`. | |
* | |
* Example: | |
* | |
* ```js | |
* var blob = blobUtil.dataURLToBlob(dataURL); | |
* ``` | |
* | |
* @param dataURL - dataURL-encoded string | |
* @returns Blob | |
*/ | |
export declare function dataURLToBlob(dataURL: string): Blob; | |
/** | |
* Convert a `Blob` to a data URL string | |
* (e.g. `'data:image/png;base64,iVBORw0KG...'`). | |
* | |
* Example: | |
* | |
* ```js | |
* var dataURL = blobUtil.blobToDataURL(blob); | |
* ``` | |
* | |
* @param blob | |
* @returns Promise that resolves with the data URL string | |
*/ | |
export declare function blobToDataURL(blob: Blob): Promise<string>; | |
/** | |
* Convert an image's `src` URL to a data URL by loading the image and painting | |
* it to a `canvas`. | |
* | |
* Note: this will coerce the image to the desired content type, and it | |
* will only paint the first frame of an animated GIF. | |
* | |
* Examples: | |
* | |
* ```js | |
* blobUtil.imgSrcToDataURL('http://mysite.com/img.png').then(function (dataURL) { | |
* // success | |
* }).catch(function (err) { | |
* // error | |
* }); | |
* ``` | |
* | |
* ```js | |
* blobUtil.imgSrcToDataURL('http://some-other-site.com/img.jpg', 'image/jpeg', | |
* 'Anonymous', 1.0).then(function (dataURL) { | |
* // success | |
* }).catch(function (err) { | |
* // error | |
* }); | |
* ``` | |
* | |
* @param src - image src | |
* @param type - the content type (optional, defaults to 'image/png') | |
* @param crossOrigin - for CORS-enabled images, set this to | |
* 'Anonymous' to avoid "tainted canvas" errors | |
* @param quality - a number between 0 and 1 indicating image quality | |
* if the requested type is 'image/jpeg' or 'image/webp' | |
* @returns Promise that resolves with the data URL string | |
*/ | |
export declare function imgSrcToDataURL(src: string, type?: string, crossOrigin?: string, quality?: number): Promise<string>; | |
/** | |
* Convert a `canvas` to a `Blob`. | |
* | |
* Examples: | |
* | |
* ```js | |
* blobUtil.canvasToBlob(canvas).then(function (blob) { | |
* // success | |
* }).catch(function (err) { | |
* // error | |
* }); | |
* ``` | |
* | |
* Most browsers support converting a canvas to both `'image/png'` and `'image/jpeg'`. You may | |
* also want to try `'image/webp'`, which will work in some browsers like Chrome (and in other browsers, will just fall back to `'image/png'`): | |
* | |
* ```js | |
* blobUtil.canvasToBlob(canvas, 'image/webp').then(function (blob) { | |
* // success | |
* }).catch(function (err) { | |
* // error | |
* }); | |
* ``` | |
* | |
* @param canvas - HTMLCanvasElement | |
* @param type - the content type (optional, defaults to 'image/png') | |
* @param quality - a number between 0 and 1 indicating image quality | |
* if the requested type is 'image/jpeg' or 'image/webp' | |
* @returns Promise that resolves with the `Blob` | |
*/ | |
export declare function canvasToBlob(canvas: HTMLCanvasElement, type?: string, quality?: number): Promise<Blob>; | |
/** | |
* Convert an image's `src` URL to a `Blob` by loading the image and painting | |
* it to a `canvas`. | |
* | |
* Note: this will coerce the image to the desired content type, and it | |
* will only paint the first frame of an animated GIF. | |
* | |
* Examples: | |
* | |
* ```js | |
* blobUtil.imgSrcToBlob('http://mysite.com/img.png').then(function (blob) { | |
* // success | |
* }).catch(function (err) { | |
* // error | |
* }); | |
* ``` | |
* | |
* ```js | |
* blobUtil.imgSrcToBlob('http://some-other-site.com/img.jpg', 'image/jpeg', | |
* 'Anonymous', 1.0).then(function (blob) { | |
* // success | |
* }).catch(function (err) { | |
* // error | |
* }); | |
* ``` | |
* | |
* @param src - image src | |
* @param type - the content type (optional, defaults to 'image/png') | |
* @param crossOrigin - for CORS-enabled images, set this to | |
* 'Anonymous' to avoid "tainted canvas" errors | |
* @param quality - a number between 0 and 1 indicating image quality | |
* if the requested type is 'image/jpeg' or 'image/webp' | |
* @returns Promise that resolves with the `Blob` | |
*/ | |
export declare function imgSrcToBlob(src: string, type?: string, crossOrigin?: string, quality?: number): Promise<Blob>; | |
/** | |
* Convert an `ArrayBuffer` to a `Blob`. | |
* | |
* Example: | |
* | |
* ```js | |
* var blob = blobUtil.arrayBufferToBlob(arrayBuff, 'audio/mpeg'); | |
* ``` | |
* | |
* @param buffer | |
* @param type - the content type (optional) | |
* @returns Blob | |
*/ | |
export declare function arrayBufferToBlob(buffer: ArrayBuffer, type?: string): Blob; | |
/** | |
* Convert a `Blob` to an `ArrayBuffer`. | |
* | |
* Example: | |
* | |
* ```js | |
* blobUtil.blobToArrayBuffer(blob).then(function (arrayBuff) { | |
* // success | |
* }).catch(function (err) { | |
* // error | |
* }); | |
* ``` | |
* | |
* @param blob | |
* @returns Promise that resolves with the `ArrayBuffer` | |
*/ | |
export declare function blobToArrayBuffer(blob: Blob): Promise<ArrayBuffer>; | |
/** | |
* Convert an `ArrayBuffer` to a binary string. | |
* | |
* Example: | |
* | |
* ```js | |
* var myString = blobUtil.arrayBufferToBinaryString(arrayBuff) | |
* ``` | |
* | |
* @param buffer - array buffer | |
* @returns binary string | |
*/ | |
export declare function arrayBufferToBinaryString(buffer: ArrayBuffer): string; | |
/** | |
* Convert a binary string to an `ArrayBuffer`. | |
* | |
* ```js | |
* var myBuffer = blobUtil.binaryStringToArrayBuffer(binaryString) | |
* ``` | |
* | |
* @param binary - binary string | |
* @returns array buffer | |
*/ | |
export declare function binaryStringToArrayBuffer(binary: string): ArrayBuffer; | |