údržba
This commit is contained in:
		
							
								
								
									
										15
									
								
								CyLukTs/lukan/node_modules/blob-util/CHANGELOG.md
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								CyLukTs/lukan/node_modules/blob-util/CHANGELOG.md
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,15 @@
 | 
			
		||||
Changelog
 | 
			
		||||
====
 | 
			
		||||
 | 
			
		||||
## v2.0.0
 | 
			
		||||
 | 
			
		||||
- Removed built-in `Promise` polyfill
 | 
			
		||||
- Some APIs that returned `Promise`s now return bare values.
 | 
			
		||||
- Removed Bower support
 | 
			
		||||
- Added ES module support
 | 
			
		||||
- Added TypeScript support
 | 
			
		||||
- Added `arrayBufferToBinaryString()` and `binaryStringToArrayBuffer()`
 | 
			
		||||
 | 
			
		||||
## v1.0.0
 | 
			
		||||
 | 
			
		||||
- Initial release
 | 
			
		||||
							
								
								
									
										202
									
								
								CyLukTs/lukan/node_modules/blob-util/LICENSE
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										202
									
								
								CyLukTs/lukan/node_modules/blob-util/LICENSE
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,202 @@
 | 
			
		||||
 | 
			
		||||
                                Apache License
 | 
			
		||||
                          Version 2.0, January 2004
 | 
			
		||||
                       http://www.apache.org/licenses/
 | 
			
		||||
 | 
			
		||||
  TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
 | 
			
		||||
 | 
			
		||||
  1. Definitions.
 | 
			
		||||
 | 
			
		||||
     "License" shall mean the terms and conditions for use, reproduction,
 | 
			
		||||
     and distribution as defined by Sections 1 through 9 of this document.
 | 
			
		||||
 | 
			
		||||
     "Licensor" shall mean the copyright owner or entity authorized by
 | 
			
		||||
     the copyright owner that is granting the License.
 | 
			
		||||
 | 
			
		||||
     "Legal Entity" shall mean the union of the acting entity and all
 | 
			
		||||
     other entities that control, are controlled by, or are under common
 | 
			
		||||
     control with that entity. For the purposes of this definition,
 | 
			
		||||
     "control" means (i) the power, direct or indirect, to cause the
 | 
			
		||||
     direction or management of such entity, whether by contract or
 | 
			
		||||
     otherwise, or (ii) ownership of fifty percent (50%) or more of the
 | 
			
		||||
     outstanding shares, or (iii) beneficial ownership of such entity.
 | 
			
		||||
 | 
			
		||||
     "You" (or "Your") shall mean an individual or Legal Entity
 | 
			
		||||
     exercising permissions granted by this License.
 | 
			
		||||
 | 
			
		||||
     "Source" form shall mean the preferred form for making modifications,
 | 
			
		||||
     including but not limited to software source code, documentation
 | 
			
		||||
     source, and configuration files.
 | 
			
		||||
 | 
			
		||||
     "Object" form shall mean any form resulting from mechanical
 | 
			
		||||
     transformation or translation of a Source form, including but
 | 
			
		||||
     not limited to compiled object code, generated documentation,
 | 
			
		||||
     and conversions to other media types.
 | 
			
		||||
 | 
			
		||||
     "Work" shall mean the work of authorship, whether in Source or
 | 
			
		||||
     Object form, made available under the License, as indicated by a
 | 
			
		||||
     copyright notice that is included in or attached to the work
 | 
			
		||||
     (an example is provided in the Appendix below).
 | 
			
		||||
 | 
			
		||||
     "Derivative Works" shall mean any work, whether in Source or Object
 | 
			
		||||
     form, that is based on (or derived from) the Work and for which the
 | 
			
		||||
     editorial revisions, annotations, elaborations, or other modifications
 | 
			
		||||
     represent, as a whole, an original work of authorship. For the purposes
 | 
			
		||||
     of this License, Derivative Works shall not include works that remain
 | 
			
		||||
     separable from, or merely link (or bind by name) to the interfaces of,
 | 
			
		||||
     the Work and Derivative Works thereof.
 | 
			
		||||
 | 
			
		||||
     "Contribution" shall mean any work of authorship, including
 | 
			
		||||
     the original version of the Work and any modifications or additions
 | 
			
		||||
     to that Work or Derivative Works thereof, that is intentionally
 | 
			
		||||
     submitted to Licensor for inclusion in the Work by the copyright owner
 | 
			
		||||
     or by an individual or Legal Entity authorized to submit on behalf of
 | 
			
		||||
     the copyright owner. For the purposes of this definition, "submitted"
 | 
			
		||||
     means any form of electronic, verbal, or written communication sent
 | 
			
		||||
     to the Licensor or its representatives, including but not limited to
 | 
			
		||||
     communication on electronic mailing lists, source code control systems,
 | 
			
		||||
     and issue tracking systems that are managed by, or on behalf of, the
 | 
			
		||||
     Licensor for the purpose of discussing and improving the Work, but
 | 
			
		||||
     excluding communication that is conspicuously marked or otherwise
 | 
			
		||||
     designated in writing by the copyright owner as "Not a Contribution."
 | 
			
		||||
 | 
			
		||||
     "Contributor" shall mean Licensor and any individual or Legal Entity
 | 
			
		||||
     on behalf of whom a Contribution has been received by Licensor and
 | 
			
		||||
     subsequently incorporated within the Work.
 | 
			
		||||
 | 
			
		||||
  2. Grant of Copyright License. Subject to the terms and conditions of
 | 
			
		||||
     this License, each Contributor hereby grants to You a perpetual,
 | 
			
		||||
     worldwide, non-exclusive, no-charge, royalty-free, irrevocable
 | 
			
		||||
     copyright license to reproduce, prepare Derivative Works of,
 | 
			
		||||
     publicly display, publicly perform, sublicense, and distribute the
 | 
			
		||||
     Work and such Derivative Works in Source or Object form.
 | 
			
		||||
 | 
			
		||||
  3. Grant of Patent License. Subject to the terms and conditions of
 | 
			
		||||
     this License, each Contributor hereby grants to You a perpetual,
 | 
			
		||||
     worldwide, non-exclusive, no-charge, royalty-free, irrevocable
 | 
			
		||||
     (except as stated in this section) patent license to make, have made,
 | 
			
		||||
     use, offer to sell, sell, import, and otherwise transfer the Work,
 | 
			
		||||
     where such license applies only to those patent claims licensable
 | 
			
		||||
     by such Contributor that are necessarily infringed by their
 | 
			
		||||
     Contribution(s) alone or by combination of their Contribution(s)
 | 
			
		||||
     with the Work to which such Contribution(s) was submitted. If You
 | 
			
		||||
     institute patent litigation against any entity (including a
 | 
			
		||||
     cross-claim or counterclaim in a lawsuit) alleging that the Work
 | 
			
		||||
     or a Contribution incorporated within the Work constitutes direct
 | 
			
		||||
     or contributory patent infringement, then any patent licenses
 | 
			
		||||
     granted to You under this License for that Work shall terminate
 | 
			
		||||
     as of the date such litigation is filed.
 | 
			
		||||
 | 
			
		||||
  4. Redistribution. You may reproduce and distribute copies of the
 | 
			
		||||
     Work or Derivative Works thereof in any medium, with or without
 | 
			
		||||
     modifications, and in Source or Object form, provided that You
 | 
			
		||||
     meet the following conditions:
 | 
			
		||||
 | 
			
		||||
     (a) You must give any other recipients of the Work or
 | 
			
		||||
         Derivative Works a copy of this License; and
 | 
			
		||||
 | 
			
		||||
     (b) You must cause any modified files to carry prominent notices
 | 
			
		||||
         stating that You changed the files; and
 | 
			
		||||
 | 
			
		||||
     (c) You must retain, in the Source form of any Derivative Works
 | 
			
		||||
         that You distribute, all copyright, patent, trademark, and
 | 
			
		||||
         attribution notices from the Source form of the Work,
 | 
			
		||||
         excluding those notices that do not pertain to any part of
 | 
			
		||||
         the Derivative Works; and
 | 
			
		||||
 | 
			
		||||
     (d) If the Work includes a "NOTICE" text file as part of its
 | 
			
		||||
         distribution, then any Derivative Works that You distribute must
 | 
			
		||||
         include a readable copy of the attribution notices contained
 | 
			
		||||
         within such NOTICE file, excluding those notices that do not
 | 
			
		||||
         pertain to any part of the Derivative Works, in at least one
 | 
			
		||||
         of the following places: within a NOTICE text file distributed
 | 
			
		||||
         as part of the Derivative Works; within the Source form or
 | 
			
		||||
         documentation, if provided along with the Derivative Works; or,
 | 
			
		||||
         within a display generated by the Derivative Works, if and
 | 
			
		||||
         wherever such third-party notices normally appear. The contents
 | 
			
		||||
         of the NOTICE file are for informational purposes only and
 | 
			
		||||
         do not modify the License. You may add Your own attribution
 | 
			
		||||
         notices within Derivative Works that You distribute, alongside
 | 
			
		||||
         or as an addendum to the NOTICE text from the Work, provided
 | 
			
		||||
         that such additional attribution notices cannot be construed
 | 
			
		||||
         as modifying the License.
 | 
			
		||||
 | 
			
		||||
     You may add Your own copyright statement to Your modifications and
 | 
			
		||||
     may provide additional or different license terms and conditions
 | 
			
		||||
     for use, reproduction, or distribution of Your modifications, or
 | 
			
		||||
     for any such Derivative Works as a whole, provided Your use,
 | 
			
		||||
     reproduction, and distribution of the Work otherwise complies with
 | 
			
		||||
     the conditions stated in this License.
 | 
			
		||||
 | 
			
		||||
  5. Submission of Contributions. Unless You explicitly state otherwise,
 | 
			
		||||
     any Contribution intentionally submitted for inclusion in the Work
 | 
			
		||||
     by You to the Licensor shall be under the terms and conditions of
 | 
			
		||||
     this License, without any additional terms or conditions.
 | 
			
		||||
     Notwithstanding the above, nothing herein shall supersede or modify
 | 
			
		||||
     the terms of any separate license agreement you may have executed
 | 
			
		||||
     with Licensor regarding such Contributions.
 | 
			
		||||
 | 
			
		||||
  6. Trademarks. This License does not grant permission to use the trade
 | 
			
		||||
     names, trademarks, service marks, or product names of the Licensor,
 | 
			
		||||
     except as required for reasonable and customary use in describing the
 | 
			
		||||
     origin of the Work and reproducing the content of the NOTICE file.
 | 
			
		||||
 | 
			
		||||
  7. Disclaimer of Warranty. Unless required by applicable law or
 | 
			
		||||
     agreed to in writing, Licensor provides the Work (and each
 | 
			
		||||
     Contributor provides its Contributions) on an "AS IS" BASIS,
 | 
			
		||||
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 | 
			
		||||
     implied, including, without limitation, any warranties or conditions
 | 
			
		||||
     of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
 | 
			
		||||
     PARTICULAR PURPOSE. You are solely responsible for determining the
 | 
			
		||||
     appropriateness of using or redistributing the Work and assume any
 | 
			
		||||
     risks associated with Your exercise of permissions under this License.
 | 
			
		||||
 | 
			
		||||
  8. Limitation of Liability. In no event and under no legal theory,
 | 
			
		||||
     whether in tort (including negligence), contract, or otherwise,
 | 
			
		||||
     unless required by applicable law (such as deliberate and grossly
 | 
			
		||||
     negligent acts) or agreed to in writing, shall any Contributor be
 | 
			
		||||
     liable to You for damages, including any direct, indirect, special,
 | 
			
		||||
     incidental, or consequential damages of any character arising as a
 | 
			
		||||
     result of this License or out of the use or inability to use the
 | 
			
		||||
     Work (including but not limited to damages for loss of goodwill,
 | 
			
		||||
     work stoppage, computer failure or malfunction, or any and all
 | 
			
		||||
     other commercial damages or losses), even if such Contributor
 | 
			
		||||
     has been advised of the possibility of such damages.
 | 
			
		||||
 | 
			
		||||
  9. Accepting Warranty or Additional Liability. While redistributing
 | 
			
		||||
     the Work or Derivative Works thereof, You may choose to offer,
 | 
			
		||||
     and charge a fee for, acceptance of support, warranty, indemnity,
 | 
			
		||||
     or other liability obligations and/or rights consistent with this
 | 
			
		||||
     License. However, in accepting such obligations, You may act only
 | 
			
		||||
     on Your own behalf and on Your sole responsibility, not on behalf
 | 
			
		||||
     of any other Contributor, and only if You agree to indemnify,
 | 
			
		||||
     defend, and hold each Contributor harmless for any liability
 | 
			
		||||
     incurred by, or claims asserted against, such Contributor by reason
 | 
			
		||||
     of your accepting any such warranty or additional liability.
 | 
			
		||||
 | 
			
		||||
  END OF TERMS AND CONDITIONS
 | 
			
		||||
 | 
			
		||||
  APPENDIX: How to apply the Apache License to your work.
 | 
			
		||||
 | 
			
		||||
     To apply the Apache License to your work, attach the following
 | 
			
		||||
     boilerplate notice, with the fields enclosed by brackets "[]"
 | 
			
		||||
     replaced with your own identifying information. (Don't include
 | 
			
		||||
     the brackets!)  The text should be enclosed in the appropriate
 | 
			
		||||
     comment syntax for the file format. We also recommend that a
 | 
			
		||||
     file or class name and description of purpose be included on the
 | 
			
		||||
     same "printed page" as the copyright notice for easier
 | 
			
		||||
     identification within third-party archives.
 | 
			
		||||
 | 
			
		||||
  Copyright [yyyy] [name of copyright owner]
 | 
			
		||||
 | 
			
		||||
  Licensed under the Apache License, Version 2.0 (the "License");
 | 
			
		||||
  you may not use this file except in compliance with the License.
 | 
			
		||||
  You may obtain a copy of the License at
 | 
			
		||||
 | 
			
		||||
      http://www.apache.org/licenses/LICENSE-2.0
 | 
			
		||||
 | 
			
		||||
  Unless required by applicable law or agreed to in writing, software
 | 
			
		||||
  distributed under the License is distributed on an "AS IS" BASIS,
 | 
			
		||||
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
			
		||||
  See the License for the specific language governing permissions and
 | 
			
		||||
  limitations under the License.
 | 
			
		||||
							
								
								
									
										623
									
								
								CyLukTs/lukan/node_modules/blob-util/README.md
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										623
									
								
								CyLukTs/lukan/node_modules/blob-util/README.md
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,623 @@
 | 
			
		||||
blob-util [](https://travis-ci.org/nolanlawson/blob-util) [](http://www.typescriptlang.org/)
 | 
			
		||||
=====
 | 
			
		||||
 | 
			
		||||
`blob-util` is a [Blob](https://developer.mozilla.org/en-US/docs/Web/API/Blob?redirectlocale=en-US&redirectslug=DOM%2FBlob) library for busy people.
 | 
			
		||||
 | 
			
		||||
It offers a small set of cross-browser utilities for translating Blobs to and from different formats:
 | 
			
		||||
 | 
			
		||||
* `<img/>` tags
 | 
			
		||||
* base 64 strings
 | 
			
		||||
* binary strings
 | 
			
		||||
* ArrayBuffers
 | 
			
		||||
* data URLs
 | 
			
		||||
* canvas
 | 
			
		||||
 | 
			
		||||
It's also a good pairing with the attachment API in [PouchDB](http://pouchdb.com).
 | 
			
		||||
 | 
			
		||||
**Note**: this is a browser library. For Node.js, see [Buffers](http://nodejs.org/api/buffer.html).
 | 
			
		||||
 | 
			
		||||
**Topics**:
 | 
			
		||||
 | 
			
		||||
* [Install](#usage)
 | 
			
		||||
* [Browser support](#browser-support)
 | 
			
		||||
* [Tutorial](#tutorial)
 | 
			
		||||
* [Playground](http://nolanlawson.github.io/blob-util)
 | 
			
		||||
* [API](#api)
 | 
			
		||||
 | 
			
		||||
Install
 | 
			
		||||
------
 | 
			
		||||
 | 
			
		||||
Via npm:
 | 
			
		||||
 | 
			
		||||
```bash
 | 
			
		||||
npm install blob-util
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
ES modules are supported:
 | 
			
		||||
 | 
			
		||||
```js
 | 
			
		||||
import { canvasToBlob } from 'blob-util'
 | 
			
		||||
canvasToBlob(canvas, 'image/png').then(/* ... */)
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
Or as a script tag:
 | 
			
		||||
 | 
			
		||||
```html
 | 
			
		||||
<script src="https://unpkg.com/blob-util/dist/blob-util.min.js"></script>
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
Then it's available as a global `blobUtil` object:
 | 
			
		||||
 | 
			
		||||
```js
 | 
			
		||||
blobUtil.canvasToBlob(canvas, 'image/png').then(/* ... */)
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
Browser support
 | 
			
		||||
-----
 | 
			
		||||
 | 
			
		||||
As of v2.0.0, a built-in `Promise` polyfill is no longer provided. Assuming you provide a `Promise`
 | 
			
		||||
polyfill, the supported browsers are:
 | 
			
		||||
 | 
			
		||||
* Firefox
 | 
			
		||||
* Chrome
 | 
			
		||||
* Edge
 | 
			
		||||
* IE 10+
 | 
			
		||||
* Safari 6+
 | 
			
		||||
* iOS 6+
 | 
			
		||||
* Android 4+
 | 
			
		||||
* Any browser with either `Blob` or the older `BlobBuilder`; see [caniuse](http://caniuse.com/#search=blob) for details.
 | 
			
		||||
 | 
			
		||||
Tutorial
 | 
			
		||||
--------
 | 
			
		||||
 | 
			
		||||
Blobs (<strong>b</strong>inary <strong>l</strong>arge <strong>ob</strong>jects) are the modern way of working with binary data in the browser. The browser support is [very good](http://caniuse.com/#search=blob).
 | 
			
		||||
 | 
			
		||||
Once you have a Blob, you can make it available offline by storing it in [IndexedDB](http://www.w3.org/TR/IndexedDB/), [PouchDB](http://pouchdb.com/), [LocalForage](https://mozilla.github.io/localForage/), or other in-browser databases. So it's the perfect format for working with offline images, sound, and video.
 | 
			
		||||
 | 
			
		||||
A [File](https://developer.mozilla.org/en-US/docs/Web/API/File) is also a Blob. So if you have an `<input type="file">` in your page, you can let your users upload any file and then work with it as a Blob.
 | 
			
		||||
 | 
			
		||||
### Example
 | 
			
		||||
 | 
			
		||||
Here's Kirby. He's a famous little Blob.
 | 
			
		||||
 | 
			
		||||
<img id="kirby" alt="Kirby" src="./test/kirby.gif"/>
 | 
			
		||||
 | 
			
		||||
So let's fulfill his destiny, and convert him to a real `Blob` object.
 | 
			
		||||
 | 
			
		||||
```js
 | 
			
		||||
var img = document.getElementById('kirby');
 | 
			
		||||
 | 
			
		||||
blobUtil.imgSrcToBlob(img.src).then(function (blob) {
 | 
			
		||||
  // ladies and gents, we have a blob
 | 
			
		||||
}).catch(function (err) {
 | 
			
		||||
  // image failed to load
 | 
			
		||||
});
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
(Don't worry, this won't download the image twice, because browsers are smart.)
 | 
			
		||||
 | 
			
		||||
Now that we have a `Blob`, we can convert it to a URL and use that as the source for another `<img/>` tag:
 | 
			
		||||
 | 
			
		||||
```js
 | 
			
		||||
var blobURL = blobUtil.createObjectURL(blob);
 | 
			
		||||
 | 
			
		||||
var newImg = document.createElement('img');
 | 
			
		||||
newImg.src = blobURL;
 | 
			
		||||
 | 
			
		||||
document.body.appendChild(newImg);
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
So now we have two Kirbys - one with a normal URL, and the other with a blob URL. You can try this out yourself in the [blob-util playground](http://nolanlawson.github.io/blob-util). Super fun!
 | 
			
		||||
 | 
			
		||||
<img src="blob-util.gif"/>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
API
 | 
			
		||||
-------
 | 
			
		||||
 | 
			
		||||
<!-- begin insert API -->
 | 
			
		||||
 | 
			
		||||
## Index
 | 
			
		||||
 | 
			
		||||
### Functions
 | 
			
		||||
 | 
			
		||||
* [arrayBufferToBinaryString](#arraybuffertobinarystring)
 | 
			
		||||
* [arrayBufferToBlob](#arraybuffertoblob)
 | 
			
		||||
* [base64StringToBlob](#base64stringtoblob)
 | 
			
		||||
* [binaryStringToArrayBuffer](#binarystringtoarraybuffer)
 | 
			
		||||
* [binaryStringToBlob](#binarystringtoblob)
 | 
			
		||||
* [blobToArrayBuffer](#blobtoarraybuffer)
 | 
			
		||||
* [blobToBase64String](#blobtobase64string)
 | 
			
		||||
* [blobToBinaryString](#blobtobinarystring)
 | 
			
		||||
* [blobToDataURL](#blobtodataurl)
 | 
			
		||||
* [canvasToBlob](#canvastoblob)
 | 
			
		||||
* [createBlob](#createblob)
 | 
			
		||||
* [createObjectURL](#createobjecturl)
 | 
			
		||||
* [dataURLToBlob](#dataurltoblob)
 | 
			
		||||
* [imgSrcToBlob](#imgsrctoblob)
 | 
			
		||||
* [imgSrcToDataURL](#imgsrctodataurl)
 | 
			
		||||
* [revokeObjectURL](#revokeobjecturl)
 | 
			
		||||
 | 
			
		||||
---
 | 
			
		||||
 | 
			
		||||
## Functions
 | 
			
		||||
 | 
			
		||||
<a id="arraybuffertobinarystring"></a>
 | 
			
		||||
 | 
			
		||||
###  arrayBufferToBinaryString
 | 
			
		||||
 | 
			
		||||
▸ **arrayBufferToBinaryString**(buffer: *`ArrayBuffer`*): `string`
 | 
			
		||||
 | 
			
		||||
Convert an `ArrayBuffer` to a binary string.
 | 
			
		||||
 | 
			
		||||
Example:
 | 
			
		||||
 | 
			
		||||
```js
 | 
			
		||||
var myString = blobUtil.arrayBufferToBinaryString(arrayBuff)
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
**Parameters:**
 | 
			
		||||
 | 
			
		||||
| Param | Type | Description |
 | 
			
		||||
| ------ | ------ | ------ |
 | 
			
		||||
| buffer | `ArrayBuffer` |  array buffer |
 | 
			
		||||
 | 
			
		||||
**Returns:** `string`
 | 
			
		||||
binary string
 | 
			
		||||
 | 
			
		||||
___
 | 
			
		||||
<a id="arraybuffertoblob"></a>
 | 
			
		||||
 | 
			
		||||
###  arrayBufferToBlob
 | 
			
		||||
 | 
			
		||||
▸ **arrayBufferToBlob**(buffer: *`ArrayBuffer`*, type?: *`string`*): `Blob`
 | 
			
		||||
 | 
			
		||||
Convert an `ArrayBuffer` to a `Blob`.
 | 
			
		||||
 | 
			
		||||
Example:
 | 
			
		||||
 | 
			
		||||
```js
 | 
			
		||||
var blob = blobUtil.arrayBufferToBlob(arrayBuff, 'audio/mpeg');
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
**Parameters:**
 | 
			
		||||
 | 
			
		||||
| Param | Type | Description |
 | 
			
		||||
| ------ | ------ | ------ |
 | 
			
		||||
| buffer | `ArrayBuffer` |  - |
 | 
			
		||||
| `Optional` type | `string` |  the content type (optional) |
 | 
			
		||||
 | 
			
		||||
**Returns:** `Blob`
 | 
			
		||||
Blob
 | 
			
		||||
 | 
			
		||||
___
 | 
			
		||||
<a id="base64stringtoblob"></a>
 | 
			
		||||
 | 
			
		||||
###  base64StringToBlob
 | 
			
		||||
 | 
			
		||||
▸ **base64StringToBlob**(base64: *`string`*, type?: *`string`*): `Blob`
 | 
			
		||||
 | 
			
		||||
Convert a base64-encoded string to a `Blob`.
 | 
			
		||||
 | 
			
		||||
Example:
 | 
			
		||||
 | 
			
		||||
```js
 | 
			
		||||
var blob = blobUtil.base64StringToBlob(base64String);
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
**Parameters:**
 | 
			
		||||
 | 
			
		||||
| Param | Type | Description |
 | 
			
		||||
| ------ | ------ | ------ |
 | 
			
		||||
| base64 | `string` |  base64-encoded string |
 | 
			
		||||
| `Optional` type | `string` |  the content type (optional) |
 | 
			
		||||
 | 
			
		||||
**Returns:** `Blob`
 | 
			
		||||
Blob
 | 
			
		||||
 | 
			
		||||
___
 | 
			
		||||
<a id="binarystringtoarraybuffer"></a>
 | 
			
		||||
 | 
			
		||||
###  binaryStringToArrayBuffer
 | 
			
		||||
 | 
			
		||||
▸ **binaryStringToArrayBuffer**(binary: *`string`*): `ArrayBuffer`
 | 
			
		||||
 | 
			
		||||
Convert a binary string to an `ArrayBuffer`.
 | 
			
		||||
 | 
			
		||||
```js
 | 
			
		||||
var myBuffer = blobUtil.binaryStringToArrayBuffer(binaryString)
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
**Parameters:**
 | 
			
		||||
 | 
			
		||||
| Param | Type | Description |
 | 
			
		||||
| ------ | ------ | ------ |
 | 
			
		||||
| binary | `string` |  binary string |
 | 
			
		||||
 | 
			
		||||
**Returns:** `ArrayBuffer`
 | 
			
		||||
array buffer
 | 
			
		||||
 | 
			
		||||
___
 | 
			
		||||
<a id="binarystringtoblob"></a>
 | 
			
		||||
 | 
			
		||||
###  binaryStringToBlob
 | 
			
		||||
 | 
			
		||||
▸ **binaryStringToBlob**(binary: *`string`*, type?: *`string`*): `Blob`
 | 
			
		||||
 | 
			
		||||
Convert a binary string to a `Blob`.
 | 
			
		||||
 | 
			
		||||
Example:
 | 
			
		||||
 | 
			
		||||
```js
 | 
			
		||||
var blob = blobUtil.binaryStringToBlob(binaryString);
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
**Parameters:**
 | 
			
		||||
 | 
			
		||||
| Param | Type | Description |
 | 
			
		||||
| ------ | ------ | ------ |
 | 
			
		||||
| binary | `string` |  binary string |
 | 
			
		||||
| `Optional` type | `string` |  the content type (optional) |
 | 
			
		||||
 | 
			
		||||
**Returns:** `Blob`
 | 
			
		||||
Blob
 | 
			
		||||
 | 
			
		||||
___
 | 
			
		||||
<a id="blobtoarraybuffer"></a>
 | 
			
		||||
 | 
			
		||||
###  blobToArrayBuffer
 | 
			
		||||
 | 
			
		||||
▸ **blobToArrayBuffer**(blob: *`Blob`*): `Promise`<`ArrayBuffer`>
 | 
			
		||||
 | 
			
		||||
Convert a `Blob` to an `ArrayBuffer`.
 | 
			
		||||
 | 
			
		||||
Example:
 | 
			
		||||
 | 
			
		||||
```js
 | 
			
		||||
blobUtil.blobToArrayBuffer(blob).then(function (arrayBuff) {
 | 
			
		||||
  // success
 | 
			
		||||
}).catch(function (err) {
 | 
			
		||||
  // error
 | 
			
		||||
});
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
**Parameters:**
 | 
			
		||||
 | 
			
		||||
| Param | Type | Description |
 | 
			
		||||
| ------ | ------ | ------ |
 | 
			
		||||
| blob | `Blob` |  - |
 | 
			
		||||
 | 
			
		||||
**Returns:** `Promise`<`ArrayBuffer`>
 | 
			
		||||
Promise that resolves with the `ArrayBuffer`
 | 
			
		||||
 | 
			
		||||
___
 | 
			
		||||
<a id="blobtobase64string"></a>
 | 
			
		||||
 | 
			
		||||
###  blobToBase64String
 | 
			
		||||
 | 
			
		||||
▸ **blobToBase64String**(blob: *`Blob`*): `Promise`<`string`>
 | 
			
		||||
 | 
			
		||||
Convert a `Blob` to a binary string.
 | 
			
		||||
 | 
			
		||||
Example:
 | 
			
		||||
 | 
			
		||||
```js
 | 
			
		||||
blobUtil.blobToBase64String(blob).then(function (base64String) {
 | 
			
		||||
  // success
 | 
			
		||||
}).catch(function (err) {
 | 
			
		||||
  // error
 | 
			
		||||
});
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
**Parameters:**
 | 
			
		||||
 | 
			
		||||
| Param | Type | Description |
 | 
			
		||||
| ------ | ------ | ------ |
 | 
			
		||||
| blob | `Blob` |  - |
 | 
			
		||||
 | 
			
		||||
**Returns:** `Promise`<`string`>
 | 
			
		||||
Promise that resolves with the binary string
 | 
			
		||||
 | 
			
		||||
___
 | 
			
		||||
<a id="blobtobinarystring"></a>
 | 
			
		||||
 | 
			
		||||
###  blobToBinaryString
 | 
			
		||||
 | 
			
		||||
▸ **blobToBinaryString**(blob: *`Blob`*): `Promise`<`string`>
 | 
			
		||||
 | 
			
		||||
Convert a `Blob` to a binary string.
 | 
			
		||||
 | 
			
		||||
Example:
 | 
			
		||||
 | 
			
		||||
```js
 | 
			
		||||
blobUtil.blobToBinaryString(blob).then(function (binaryString) {
 | 
			
		||||
  // success
 | 
			
		||||
}).catch(function (err) {
 | 
			
		||||
  // error
 | 
			
		||||
});
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
**Parameters:**
 | 
			
		||||
 | 
			
		||||
| Param | Type | Description |
 | 
			
		||||
| ------ | ------ | ------ |
 | 
			
		||||
| blob | `Blob` |  - |
 | 
			
		||||
 | 
			
		||||
**Returns:** `Promise`<`string`>
 | 
			
		||||
Promise that resolves with the binary string
 | 
			
		||||
 | 
			
		||||
___
 | 
			
		||||
<a id="blobtodataurl"></a>
 | 
			
		||||
 | 
			
		||||
###  blobToDataURL
 | 
			
		||||
 | 
			
		||||
▸ **blobToDataURL**(blob: *`Blob`*): `Promise`<`string`>
 | 
			
		||||
 | 
			
		||||
Convert a `Blob` to a data URL string (e.g. `'data:image/png;base64,iVBORw0KG...'`).
 | 
			
		||||
 | 
			
		||||
Example:
 | 
			
		||||
 | 
			
		||||
```js
 | 
			
		||||
var dataURL = blobUtil.blobToDataURL(blob);
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
**Parameters:**
 | 
			
		||||
 | 
			
		||||
| Param | Type | Description |
 | 
			
		||||
| ------ | ------ | ------ |
 | 
			
		||||
| blob | `Blob` |  - |
 | 
			
		||||
 | 
			
		||||
**Returns:** `Promise`<`string`>
 | 
			
		||||
Promise that resolves with the data URL string
 | 
			
		||||
 | 
			
		||||
___
 | 
			
		||||
<a id="canvastoblob"></a>
 | 
			
		||||
 | 
			
		||||
###  canvasToBlob
 | 
			
		||||
 | 
			
		||||
▸ **canvasToBlob**(canvas: *`HTMLCanvasElement`*, type?: *`string`*, quality?: *`number`*): `Promise`<`Blob`>
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
});
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
**Parameters:**
 | 
			
		||||
 | 
			
		||||
| Param | Type | Description |
 | 
			
		||||
| ------ | ------ | ------ |
 | 
			
		||||
| canvas | `HTMLCanvasElement` |  HTMLCanvasElement |
 | 
			
		||||
| `Optional` type | `string` |  the content type (optional, defaults to 'image/png') |
 | 
			
		||||
| `Optional` quality | `number` |  a number between 0 and 1 indicating image quality if the requested type is 'image/jpeg' or 'image/webp' |
 | 
			
		||||
 | 
			
		||||
**Returns:** `Promise`<`Blob`>
 | 
			
		||||
Promise that resolves with the `Blob`
 | 
			
		||||
 | 
			
		||||
___
 | 
			
		||||
<a id="createblob"></a>
 | 
			
		||||
 | 
			
		||||
###  createBlob
 | 
			
		||||
 | 
			
		||||
▸ **createBlob**(parts: *`Array`<`any`>*, properties?: * `BlobPropertyBag` | `string`*): `Blob`
 | 
			
		||||
 | 
			
		||||
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'});
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
**Parameters:**
 | 
			
		||||
 | 
			
		||||
| Param | Type | Description |
 | 
			
		||||
| ------ | ------ | ------ |
 | 
			
		||||
| parts | `Array`<`any`> |  content of the Blob |
 | 
			
		||||
| `Optional` properties |  `BlobPropertyBag` | `string`|  usually `{type: myContentType}`, you can also pass a string for the content type |
 | 
			
		||||
 | 
			
		||||
**Returns:** `Blob`
 | 
			
		||||
Blob
 | 
			
		||||
 | 
			
		||||
___
 | 
			
		||||
<a id="createobjecturl"></a>
 | 
			
		||||
 | 
			
		||||
###  createObjectURL
 | 
			
		||||
 | 
			
		||||
▸ **createObjectURL**(blob: *`Blob`*): `string`
 | 
			
		||||
 | 
			
		||||
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);
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
**Parameters:**
 | 
			
		||||
 | 
			
		||||
| Param | Type | Description |
 | 
			
		||||
| ------ | ------ | ------ |
 | 
			
		||||
| blob | `Blob` |  - |
 | 
			
		||||
 | 
			
		||||
**Returns:** `string`
 | 
			
		||||
url
 | 
			
		||||
 | 
			
		||||
___
 | 
			
		||||
<a id="dataurltoblob"></a>
 | 
			
		||||
 | 
			
		||||
###  dataURLToBlob
 | 
			
		||||
 | 
			
		||||
▸ **dataURLToBlob**(dataURL: *`string`*): `Blob`
 | 
			
		||||
 | 
			
		||||
Convert a data URL string (e.g. `'data:image/png;base64,iVBORw0KG...'`) to a `Blob`.
 | 
			
		||||
 | 
			
		||||
Example:
 | 
			
		||||
 | 
			
		||||
```js
 | 
			
		||||
var blob = blobUtil.dataURLToBlob(dataURL);
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
**Parameters:**
 | 
			
		||||
 | 
			
		||||
| Param | Type | Description |
 | 
			
		||||
| ------ | ------ | ------ |
 | 
			
		||||
| dataURL | `string` |  dataURL-encoded string |
 | 
			
		||||
 | 
			
		||||
**Returns:** `Blob`
 | 
			
		||||
Blob
 | 
			
		||||
 | 
			
		||||
___
 | 
			
		||||
<a id="imgsrctoblob"></a>
 | 
			
		||||
 | 
			
		||||
###  imgSrcToBlob
 | 
			
		||||
 | 
			
		||||
▸ **imgSrcToBlob**(src: *`string`*, type?: *`string`*, crossOrigin?: *`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
 | 
			
		||||
});
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
**Parameters:**
 | 
			
		||||
 | 
			
		||||
| Param | Type | Description |
 | 
			
		||||
| ------ | ------ | ------ |
 | 
			
		||||
| src | `string` |  image src |
 | 
			
		||||
| `Optional` type | `string` |  the content type (optional, defaults to 'image/png') |
 | 
			
		||||
| `Optional` crossOrigin | `string` |  for CORS-enabled images, set this to 'Anonymous' to avoid "tainted canvas" errors |
 | 
			
		||||
| `Optional` quality | `number` |  a number between 0 and 1 indicating image quality if the requested type is 'image/jpeg' or 'image/webp' |
 | 
			
		||||
 | 
			
		||||
**Returns:** `Promise`<`Blob`>
 | 
			
		||||
Promise that resolves with the `Blob`
 | 
			
		||||
 | 
			
		||||
___
 | 
			
		||||
<a id="imgsrctodataurl"></a>
 | 
			
		||||
 | 
			
		||||
###  imgSrcToDataURL
 | 
			
		||||
 | 
			
		||||
▸ **imgSrcToDataURL**(src: *`string`*, type?: *`string`*, crossOrigin?: *`string`*, quality?: *`number`*): `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
 | 
			
		||||
});
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
**Parameters:**
 | 
			
		||||
 | 
			
		||||
| Param | Type | Description |
 | 
			
		||||
| ------ | ------ | ------ |
 | 
			
		||||
| src | `string` |  image src |
 | 
			
		||||
| `Optional` type | `string` |  the content type (optional, defaults to 'image/png') |
 | 
			
		||||
| `Optional` crossOrigin | `string` |  for CORS-enabled images, set this to 'Anonymous' to avoid "tainted canvas" errors |
 | 
			
		||||
| `Optional` quality | `number` |  a number between 0 and 1 indicating image quality if the requested type is 'image/jpeg' or 'image/webp' |
 | 
			
		||||
 | 
			
		||||
**Returns:** `Promise`<`string`>
 | 
			
		||||
Promise that resolves with the data URL string
 | 
			
		||||
 | 
			
		||||
___
 | 
			
		||||
<a id="revokeobjecturl"></a>
 | 
			
		||||
 | 
			
		||||
###  revokeObjectURL
 | 
			
		||||
 | 
			
		||||
▸ **revokeObjectURL**(url: *`string`*): `void`
 | 
			
		||||
 | 
			
		||||
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);
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
**Parameters:**
 | 
			
		||||
 | 
			
		||||
| Param | Type | Description |
 | 
			
		||||
| ------ | ------ | ------ |
 | 
			
		||||
| url | `string` |   |
 | 
			
		||||
 | 
			
		||||
**Returns:** `void`
 | 
			
		||||
 | 
			
		||||
___
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
<!-- end insert API -->
 | 
			
		||||
 | 
			
		||||
Credits
 | 
			
		||||
----
 | 
			
		||||
 | 
			
		||||
Thanks to the rest of [the PouchDB team](https://github.com/pouchdb/pouchdb/graphs/contributors) for figuring most of this crazy stuff out.
 | 
			
		||||
 | 
			
		||||
Building the library
 | 
			
		||||
----
 | 
			
		||||
 | 
			
		||||
    npm install
 | 
			
		||||
    npm run build
 | 
			
		||||
 | 
			
		||||
Testing the library
 | 
			
		||||
----
 | 
			
		||||
 | 
			
		||||
    npm install
 | 
			
		||||
 | 
			
		||||
Then to test in the browser using Saucelabs:
 | 
			
		||||
 | 
			
		||||
    npm test
 | 
			
		||||
 | 
			
		||||
Or to test locally in your browser of choice:
 | 
			
		||||
 | 
			
		||||
    npm run test-local
 | 
			
		||||
 | 
			
		||||
To build the API docs and insert them in the README:
 | 
			
		||||
 | 
			
		||||
    npm run doc
 | 
			
		||||
							
								
								
									
										454
									
								
								CyLukTs/lukan/node_modules/blob-util/dist/blob-util.cjs.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										454
									
								
								CyLukTs/lukan/node_modules/blob-util/dist/blob-util.cjs.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,454 @@
 | 
			
		||||
'use strict';
 | 
			
		||||
 | 
			
		||||
Object.defineProperty(exports, '__esModule', { value: true });
 | 
			
		||||
 | 
			
		||||
// TODO: including these in blob-util.ts causes typedoc to generate docs for them,
 | 
			
		||||
// even with --excludePrivate ¯\_(ツ)_/¯
 | 
			
		||||
/** @private */
 | 
			
		||||
function loadImage(src, crossOrigin) {
 | 
			
		||||
    return new Promise(function (resolve, reject) {
 | 
			
		||||
        var img = new Image();
 | 
			
		||||
        if (crossOrigin) {
 | 
			
		||||
            img.crossOrigin = crossOrigin;
 | 
			
		||||
        }
 | 
			
		||||
        img.onload = function () {
 | 
			
		||||
            resolve(img);
 | 
			
		||||
        };
 | 
			
		||||
        img.onerror = reject;
 | 
			
		||||
        img.src = src;
 | 
			
		||||
    });
 | 
			
		||||
}
 | 
			
		||||
/** @private */
 | 
			
		||||
function imgToCanvas(img) {
 | 
			
		||||
    var canvas = document.createElement('canvas');
 | 
			
		||||
    canvas.width = img.width;
 | 
			
		||||
    canvas.height = img.height;
 | 
			
		||||
    // copy the image contents to the canvas
 | 
			
		||||
    var context = canvas.getContext('2d');
 | 
			
		||||
    context.drawImage(img, 0, 0, img.width, img.height, 0, 0, img.width, img.height);
 | 
			
		||||
    return canvas;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* global Promise, Image, Blob, FileReader, atob, btoa,
 | 
			
		||||
   BlobBuilder, MSBlobBuilder, MozBlobBuilder, WebKitBlobBuilder, webkitURL */
 | 
			
		||||
/**
 | 
			
		||||
 * 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
 | 
			
		||||
 */
 | 
			
		||||
function createBlob(parts, properties) {
 | 
			
		||||
    parts = parts || [];
 | 
			
		||||
    properties = properties || {};
 | 
			
		||||
    if (typeof properties === 'string') {
 | 
			
		||||
        properties = { type: properties }; // infer content type
 | 
			
		||||
    }
 | 
			
		||||
    try {
 | 
			
		||||
        return new Blob(parts, properties);
 | 
			
		||||
    }
 | 
			
		||||
    catch (e) {
 | 
			
		||||
        if (e.name !== 'TypeError') {
 | 
			
		||||
            throw e;
 | 
			
		||||
        }
 | 
			
		||||
        var Builder = typeof BlobBuilder !== 'undefined'
 | 
			
		||||
            ? BlobBuilder : typeof MSBlobBuilder !== 'undefined'
 | 
			
		||||
            ? MSBlobBuilder : typeof MozBlobBuilder !== 'undefined'
 | 
			
		||||
            ? MozBlobBuilder : WebKitBlobBuilder;
 | 
			
		||||
        var builder = new Builder();
 | 
			
		||||
        for (var i = 0; i < parts.length; i += 1) {
 | 
			
		||||
            builder.append(parts[i]);
 | 
			
		||||
        }
 | 
			
		||||
        return builder.getBlob(properties.type);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
/**
 | 
			
		||||
 * 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
 | 
			
		||||
 */
 | 
			
		||||
function createObjectURL(blob) {
 | 
			
		||||
    return (typeof URL !== 'undefined' ? URL : webkitURL).createObjectURL(blob);
 | 
			
		||||
}
 | 
			
		||||
/**
 | 
			
		||||
 * 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
 | 
			
		||||
 */
 | 
			
		||||
function revokeObjectURL(url) {
 | 
			
		||||
    return (typeof URL !== 'undefined' ? URL : webkitURL).revokeObjectURL(url);
 | 
			
		||||
}
 | 
			
		||||
/**
 | 
			
		||||
 * 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
 | 
			
		||||
 */
 | 
			
		||||
function blobToBinaryString(blob) {
 | 
			
		||||
    return new Promise(function (resolve, reject) {
 | 
			
		||||
        var reader = new FileReader();
 | 
			
		||||
        var hasBinaryString = typeof reader.readAsBinaryString === 'function';
 | 
			
		||||
        reader.onloadend = function () {
 | 
			
		||||
            var result = reader.result || '';
 | 
			
		||||
            if (hasBinaryString) {
 | 
			
		||||
                return resolve(result);
 | 
			
		||||
            }
 | 
			
		||||
            resolve(arrayBufferToBinaryString(result));
 | 
			
		||||
        };
 | 
			
		||||
        reader.onerror = reject;
 | 
			
		||||
        if (hasBinaryString) {
 | 
			
		||||
            reader.readAsBinaryString(blob);
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            reader.readAsArrayBuffer(blob);
 | 
			
		||||
        }
 | 
			
		||||
    });
 | 
			
		||||
}
 | 
			
		||||
/**
 | 
			
		||||
 * 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
 | 
			
		||||
 */
 | 
			
		||||
function base64StringToBlob(base64, type) {
 | 
			
		||||
    var parts = [binaryStringToArrayBuffer(atob(base64))];
 | 
			
		||||
    return type ? createBlob(parts, { type: type }) : createBlob(parts);
 | 
			
		||||
}
 | 
			
		||||
/**
 | 
			
		||||
 * 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
 | 
			
		||||
 */
 | 
			
		||||
function binaryStringToBlob(binary, type) {
 | 
			
		||||
    return base64StringToBlob(btoa(binary), type);
 | 
			
		||||
}
 | 
			
		||||
/**
 | 
			
		||||
 * 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
 | 
			
		||||
 */
 | 
			
		||||
function blobToBase64String(blob) {
 | 
			
		||||
    return blobToBinaryString(blob).then(btoa);
 | 
			
		||||
}
 | 
			
		||||
/**
 | 
			
		||||
 * 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
 | 
			
		||||
 */
 | 
			
		||||
function dataURLToBlob(dataURL) {
 | 
			
		||||
    var type = dataURL.match(/data:([^;]+)/)[1];
 | 
			
		||||
    var base64 = dataURL.replace(/^[^,]+,/, '');
 | 
			
		||||
    var buff = binaryStringToArrayBuffer(atob(base64));
 | 
			
		||||
    return createBlob([buff], { type: type });
 | 
			
		||||
}
 | 
			
		||||
/**
 | 
			
		||||
 * 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
 | 
			
		||||
 */
 | 
			
		||||
function blobToDataURL(blob) {
 | 
			
		||||
    return blobToBase64String(blob).then(function (base64String) {
 | 
			
		||||
        return 'data:' + blob.type + ';base64,' + base64String;
 | 
			
		||||
    });
 | 
			
		||||
}
 | 
			
		||||
/**
 | 
			
		||||
 * 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
 | 
			
		||||
 */
 | 
			
		||||
function imgSrcToDataURL(src, type, crossOrigin, quality) {
 | 
			
		||||
    type = type || 'image/png';
 | 
			
		||||
    return loadImage(src, crossOrigin).then(imgToCanvas).then(function (canvas) {
 | 
			
		||||
        return canvas.toDataURL(type, quality);
 | 
			
		||||
    });
 | 
			
		||||
}
 | 
			
		||||
/**
 | 
			
		||||
 * 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`
 | 
			
		||||
 */
 | 
			
		||||
function canvasToBlob(canvas, type, quality) {
 | 
			
		||||
    if (typeof canvas.toBlob === 'function') {
 | 
			
		||||
        return new Promise(function (resolve) {
 | 
			
		||||
            canvas.toBlob(resolve, type, quality);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
    return Promise.resolve(dataURLToBlob(canvas.toDataURL(type, quality)));
 | 
			
		||||
}
 | 
			
		||||
/**
 | 
			
		||||
 * 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`
 | 
			
		||||
 */
 | 
			
		||||
function imgSrcToBlob(src, type, crossOrigin, quality) {
 | 
			
		||||
    type = type || 'image/png';
 | 
			
		||||
    return loadImage(src, crossOrigin).then(imgToCanvas).then(function (canvas) {
 | 
			
		||||
        return canvasToBlob(canvas, type, quality);
 | 
			
		||||
    });
 | 
			
		||||
}
 | 
			
		||||
/**
 | 
			
		||||
 * 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
 | 
			
		||||
 */
 | 
			
		||||
function arrayBufferToBlob(buffer, type) {
 | 
			
		||||
    return createBlob([buffer], type);
 | 
			
		||||
}
 | 
			
		||||
/**
 | 
			
		||||
 * 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`
 | 
			
		||||
 */
 | 
			
		||||
function blobToArrayBuffer(blob) {
 | 
			
		||||
    return new Promise(function (resolve, reject) {
 | 
			
		||||
        var reader = new FileReader();
 | 
			
		||||
        reader.onloadend = function () {
 | 
			
		||||
            var result = reader.result || new ArrayBuffer(0);
 | 
			
		||||
            resolve(result);
 | 
			
		||||
        };
 | 
			
		||||
        reader.onerror = reject;
 | 
			
		||||
        reader.readAsArrayBuffer(blob);
 | 
			
		||||
    });
 | 
			
		||||
}
 | 
			
		||||
/**
 | 
			
		||||
 * Convert an `ArrayBuffer` to a binary string.
 | 
			
		||||
 *
 | 
			
		||||
 * Example:
 | 
			
		||||
 *
 | 
			
		||||
 * ```js
 | 
			
		||||
 * var myString = blobUtil.arrayBufferToBinaryString(arrayBuff)
 | 
			
		||||
 * ```
 | 
			
		||||
 *
 | 
			
		||||
 * @param buffer - array buffer
 | 
			
		||||
 * @returns binary string
 | 
			
		||||
 */
 | 
			
		||||
function arrayBufferToBinaryString(buffer) {
 | 
			
		||||
    var binary = '';
 | 
			
		||||
    var bytes = new Uint8Array(buffer);
 | 
			
		||||
    var length = bytes.byteLength;
 | 
			
		||||
    var i = -1;
 | 
			
		||||
    while (++i < length) {
 | 
			
		||||
        binary += String.fromCharCode(bytes[i]);
 | 
			
		||||
    }
 | 
			
		||||
    return binary;
 | 
			
		||||
}
 | 
			
		||||
/**
 | 
			
		||||
 * Convert a binary string to an `ArrayBuffer`.
 | 
			
		||||
 *
 | 
			
		||||
 * ```js
 | 
			
		||||
 * var myBuffer = blobUtil.binaryStringToArrayBuffer(binaryString)
 | 
			
		||||
 * ```
 | 
			
		||||
 *
 | 
			
		||||
 * @param binary - binary string
 | 
			
		||||
 * @returns array buffer
 | 
			
		||||
 */
 | 
			
		||||
function binaryStringToArrayBuffer(binary) {
 | 
			
		||||
    var length = binary.length;
 | 
			
		||||
    var buf = new ArrayBuffer(length);
 | 
			
		||||
    var arr = new Uint8Array(buf);
 | 
			
		||||
    var i = -1;
 | 
			
		||||
    while (++i < length) {
 | 
			
		||||
        arr[i] = binary.charCodeAt(i);
 | 
			
		||||
    }
 | 
			
		||||
    return buf;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
exports.createBlob = createBlob;
 | 
			
		||||
exports.createObjectURL = createObjectURL;
 | 
			
		||||
exports.revokeObjectURL = revokeObjectURL;
 | 
			
		||||
exports.blobToBinaryString = blobToBinaryString;
 | 
			
		||||
exports.base64StringToBlob = base64StringToBlob;
 | 
			
		||||
exports.binaryStringToBlob = binaryStringToBlob;
 | 
			
		||||
exports.blobToBase64String = blobToBase64String;
 | 
			
		||||
exports.dataURLToBlob = dataURLToBlob;
 | 
			
		||||
exports.blobToDataURL = blobToDataURL;
 | 
			
		||||
exports.imgSrcToDataURL = imgSrcToDataURL;
 | 
			
		||||
exports.canvasToBlob = canvasToBlob;
 | 
			
		||||
exports.imgSrcToBlob = imgSrcToBlob;
 | 
			
		||||
exports.arrayBufferToBlob = arrayBufferToBlob;
 | 
			
		||||
exports.blobToArrayBuffer = blobToArrayBuffer;
 | 
			
		||||
exports.arrayBufferToBinaryString = arrayBufferToBinaryString;
 | 
			
		||||
exports.binaryStringToArrayBuffer = binaryStringToArrayBuffer;
 | 
			
		||||
							
								
								
									
										295
									
								
								CyLukTs/lukan/node_modules/blob-util/dist/blob-util.d.ts
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										295
									
								
								CyLukTs/lukan/node_modules/blob-util/dist/blob-util.d.ts
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,295 @@
 | 
			
		||||
/**
 | 
			
		||||
 * 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;
 | 
			
		||||
							
								
								
									
										435
									
								
								CyLukTs/lukan/node_modules/blob-util/dist/blob-util.es.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										435
									
								
								CyLukTs/lukan/node_modules/blob-util/dist/blob-util.es.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,435 @@
 | 
			
		||||
// TODO: including these in blob-util.ts causes typedoc to generate docs for them,
 | 
			
		||||
// even with --excludePrivate ¯\_(ツ)_/¯
 | 
			
		||||
/** @private */
 | 
			
		||||
function loadImage(src, crossOrigin) {
 | 
			
		||||
    return new Promise(function (resolve, reject) {
 | 
			
		||||
        var img = new Image();
 | 
			
		||||
        if (crossOrigin) {
 | 
			
		||||
            img.crossOrigin = crossOrigin;
 | 
			
		||||
        }
 | 
			
		||||
        img.onload = function () {
 | 
			
		||||
            resolve(img);
 | 
			
		||||
        };
 | 
			
		||||
        img.onerror = reject;
 | 
			
		||||
        img.src = src;
 | 
			
		||||
    });
 | 
			
		||||
}
 | 
			
		||||
/** @private */
 | 
			
		||||
function imgToCanvas(img) {
 | 
			
		||||
    var canvas = document.createElement('canvas');
 | 
			
		||||
    canvas.width = img.width;
 | 
			
		||||
    canvas.height = img.height;
 | 
			
		||||
    // copy the image contents to the canvas
 | 
			
		||||
    var context = canvas.getContext('2d');
 | 
			
		||||
    context.drawImage(img, 0, 0, img.width, img.height, 0, 0, img.width, img.height);
 | 
			
		||||
    return canvas;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* global Promise, Image, Blob, FileReader, atob, btoa,
 | 
			
		||||
   BlobBuilder, MSBlobBuilder, MozBlobBuilder, WebKitBlobBuilder, webkitURL */
 | 
			
		||||
/**
 | 
			
		||||
 * 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
 | 
			
		||||
 */
 | 
			
		||||
function createBlob(parts, properties) {
 | 
			
		||||
    parts = parts || [];
 | 
			
		||||
    properties = properties || {};
 | 
			
		||||
    if (typeof properties === 'string') {
 | 
			
		||||
        properties = { type: properties }; // infer content type
 | 
			
		||||
    }
 | 
			
		||||
    try {
 | 
			
		||||
        return new Blob(parts, properties);
 | 
			
		||||
    }
 | 
			
		||||
    catch (e) {
 | 
			
		||||
        if (e.name !== 'TypeError') {
 | 
			
		||||
            throw e;
 | 
			
		||||
        }
 | 
			
		||||
        var Builder = typeof BlobBuilder !== 'undefined'
 | 
			
		||||
            ? BlobBuilder : typeof MSBlobBuilder !== 'undefined'
 | 
			
		||||
            ? MSBlobBuilder : typeof MozBlobBuilder !== 'undefined'
 | 
			
		||||
            ? MozBlobBuilder : WebKitBlobBuilder;
 | 
			
		||||
        var builder = new Builder();
 | 
			
		||||
        for (var i = 0; i < parts.length; i += 1) {
 | 
			
		||||
            builder.append(parts[i]);
 | 
			
		||||
        }
 | 
			
		||||
        return builder.getBlob(properties.type);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
/**
 | 
			
		||||
 * 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
 | 
			
		||||
 */
 | 
			
		||||
function createObjectURL(blob) {
 | 
			
		||||
    return (typeof URL !== 'undefined' ? URL : webkitURL).createObjectURL(blob);
 | 
			
		||||
}
 | 
			
		||||
/**
 | 
			
		||||
 * 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
 | 
			
		||||
 */
 | 
			
		||||
function revokeObjectURL(url) {
 | 
			
		||||
    return (typeof URL !== 'undefined' ? URL : webkitURL).revokeObjectURL(url);
 | 
			
		||||
}
 | 
			
		||||
/**
 | 
			
		||||
 * 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
 | 
			
		||||
 */
 | 
			
		||||
function blobToBinaryString(blob) {
 | 
			
		||||
    return new Promise(function (resolve, reject) {
 | 
			
		||||
        var reader = new FileReader();
 | 
			
		||||
        var hasBinaryString = typeof reader.readAsBinaryString === 'function';
 | 
			
		||||
        reader.onloadend = function () {
 | 
			
		||||
            var result = reader.result || '';
 | 
			
		||||
            if (hasBinaryString) {
 | 
			
		||||
                return resolve(result);
 | 
			
		||||
            }
 | 
			
		||||
            resolve(arrayBufferToBinaryString(result));
 | 
			
		||||
        };
 | 
			
		||||
        reader.onerror = reject;
 | 
			
		||||
        if (hasBinaryString) {
 | 
			
		||||
            reader.readAsBinaryString(blob);
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            reader.readAsArrayBuffer(blob);
 | 
			
		||||
        }
 | 
			
		||||
    });
 | 
			
		||||
}
 | 
			
		||||
/**
 | 
			
		||||
 * 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
 | 
			
		||||
 */
 | 
			
		||||
function base64StringToBlob(base64, type) {
 | 
			
		||||
    var parts = [binaryStringToArrayBuffer(atob(base64))];
 | 
			
		||||
    return type ? createBlob(parts, { type: type }) : createBlob(parts);
 | 
			
		||||
}
 | 
			
		||||
/**
 | 
			
		||||
 * 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
 | 
			
		||||
 */
 | 
			
		||||
function binaryStringToBlob(binary, type) {
 | 
			
		||||
    return base64StringToBlob(btoa(binary), type);
 | 
			
		||||
}
 | 
			
		||||
/**
 | 
			
		||||
 * 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
 | 
			
		||||
 */
 | 
			
		||||
function blobToBase64String(blob) {
 | 
			
		||||
    return blobToBinaryString(blob).then(btoa);
 | 
			
		||||
}
 | 
			
		||||
/**
 | 
			
		||||
 * 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
 | 
			
		||||
 */
 | 
			
		||||
function dataURLToBlob(dataURL) {
 | 
			
		||||
    var type = dataURL.match(/data:([^;]+)/)[1];
 | 
			
		||||
    var base64 = dataURL.replace(/^[^,]+,/, '');
 | 
			
		||||
    var buff = binaryStringToArrayBuffer(atob(base64));
 | 
			
		||||
    return createBlob([buff], { type: type });
 | 
			
		||||
}
 | 
			
		||||
/**
 | 
			
		||||
 * 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
 | 
			
		||||
 */
 | 
			
		||||
function blobToDataURL(blob) {
 | 
			
		||||
    return blobToBase64String(blob).then(function (base64String) {
 | 
			
		||||
        return 'data:' + blob.type + ';base64,' + base64String;
 | 
			
		||||
    });
 | 
			
		||||
}
 | 
			
		||||
/**
 | 
			
		||||
 * 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
 | 
			
		||||
 */
 | 
			
		||||
function imgSrcToDataURL(src, type, crossOrigin, quality) {
 | 
			
		||||
    type = type || 'image/png';
 | 
			
		||||
    return loadImage(src, crossOrigin).then(imgToCanvas).then(function (canvas) {
 | 
			
		||||
        return canvas.toDataURL(type, quality);
 | 
			
		||||
    });
 | 
			
		||||
}
 | 
			
		||||
/**
 | 
			
		||||
 * 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`
 | 
			
		||||
 */
 | 
			
		||||
function canvasToBlob(canvas, type, quality) {
 | 
			
		||||
    if (typeof canvas.toBlob === 'function') {
 | 
			
		||||
        return new Promise(function (resolve) {
 | 
			
		||||
            canvas.toBlob(resolve, type, quality);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
    return Promise.resolve(dataURLToBlob(canvas.toDataURL(type, quality)));
 | 
			
		||||
}
 | 
			
		||||
/**
 | 
			
		||||
 * 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`
 | 
			
		||||
 */
 | 
			
		||||
function imgSrcToBlob(src, type, crossOrigin, quality) {
 | 
			
		||||
    type = type || 'image/png';
 | 
			
		||||
    return loadImage(src, crossOrigin).then(imgToCanvas).then(function (canvas) {
 | 
			
		||||
        return canvasToBlob(canvas, type, quality);
 | 
			
		||||
    });
 | 
			
		||||
}
 | 
			
		||||
/**
 | 
			
		||||
 * 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
 | 
			
		||||
 */
 | 
			
		||||
function arrayBufferToBlob(buffer, type) {
 | 
			
		||||
    return createBlob([buffer], type);
 | 
			
		||||
}
 | 
			
		||||
/**
 | 
			
		||||
 * 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`
 | 
			
		||||
 */
 | 
			
		||||
function blobToArrayBuffer(blob) {
 | 
			
		||||
    return new Promise(function (resolve, reject) {
 | 
			
		||||
        var reader = new FileReader();
 | 
			
		||||
        reader.onloadend = function () {
 | 
			
		||||
            var result = reader.result || new ArrayBuffer(0);
 | 
			
		||||
            resolve(result);
 | 
			
		||||
        };
 | 
			
		||||
        reader.onerror = reject;
 | 
			
		||||
        reader.readAsArrayBuffer(blob);
 | 
			
		||||
    });
 | 
			
		||||
}
 | 
			
		||||
/**
 | 
			
		||||
 * Convert an `ArrayBuffer` to a binary string.
 | 
			
		||||
 *
 | 
			
		||||
 * Example:
 | 
			
		||||
 *
 | 
			
		||||
 * ```js
 | 
			
		||||
 * var myString = blobUtil.arrayBufferToBinaryString(arrayBuff)
 | 
			
		||||
 * ```
 | 
			
		||||
 *
 | 
			
		||||
 * @param buffer - array buffer
 | 
			
		||||
 * @returns binary string
 | 
			
		||||
 */
 | 
			
		||||
function arrayBufferToBinaryString(buffer) {
 | 
			
		||||
    var binary = '';
 | 
			
		||||
    var bytes = new Uint8Array(buffer);
 | 
			
		||||
    var length = bytes.byteLength;
 | 
			
		||||
    var i = -1;
 | 
			
		||||
    while (++i < length) {
 | 
			
		||||
        binary += String.fromCharCode(bytes[i]);
 | 
			
		||||
    }
 | 
			
		||||
    return binary;
 | 
			
		||||
}
 | 
			
		||||
/**
 | 
			
		||||
 * Convert a binary string to an `ArrayBuffer`.
 | 
			
		||||
 *
 | 
			
		||||
 * ```js
 | 
			
		||||
 * var myBuffer = blobUtil.binaryStringToArrayBuffer(binaryString)
 | 
			
		||||
 * ```
 | 
			
		||||
 *
 | 
			
		||||
 * @param binary - binary string
 | 
			
		||||
 * @returns array buffer
 | 
			
		||||
 */
 | 
			
		||||
function binaryStringToArrayBuffer(binary) {
 | 
			
		||||
    var length = binary.length;
 | 
			
		||||
    var buf = new ArrayBuffer(length);
 | 
			
		||||
    var arr = new Uint8Array(buf);
 | 
			
		||||
    var i = -1;
 | 
			
		||||
    while (++i < length) {
 | 
			
		||||
        arr[i] = binary.charCodeAt(i);
 | 
			
		||||
    }
 | 
			
		||||
    return buf;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export { createBlob, createObjectURL, revokeObjectURL, blobToBinaryString, base64StringToBlob, binaryStringToBlob, blobToBase64String, dataURLToBlob, blobToDataURL, imgSrcToDataURL, canvasToBlob, imgSrcToBlob, arrayBufferToBlob, blobToArrayBuffer, arrayBufferToBinaryString, binaryStringToArrayBuffer };
 | 
			
		||||
							
								
								
									
										460
									
								
								CyLukTs/lukan/node_modules/blob-util/dist/blob-util.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										460
									
								
								CyLukTs/lukan/node_modules/blob-util/dist/blob-util.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,460 @@
 | 
			
		||||
(function (global, factory) {
 | 
			
		||||
    typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
 | 
			
		||||
    typeof define === 'function' && define.amd ? define(['exports'], factory) :
 | 
			
		||||
    (factory((global.blobUtil = {})));
 | 
			
		||||
}(this, (function (exports) { 'use strict';
 | 
			
		||||
 | 
			
		||||
    // TODO: including these in blob-util.ts causes typedoc to generate docs for them,
 | 
			
		||||
    // even with --excludePrivate ¯\_(ツ)_/¯
 | 
			
		||||
    /** @private */
 | 
			
		||||
    function loadImage(src, crossOrigin) {
 | 
			
		||||
        return new Promise(function (resolve, reject) {
 | 
			
		||||
            var img = new Image();
 | 
			
		||||
            if (crossOrigin) {
 | 
			
		||||
                img.crossOrigin = crossOrigin;
 | 
			
		||||
            }
 | 
			
		||||
            img.onload = function () {
 | 
			
		||||
                resolve(img);
 | 
			
		||||
            };
 | 
			
		||||
            img.onerror = reject;
 | 
			
		||||
            img.src = src;
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
    /** @private */
 | 
			
		||||
    function imgToCanvas(img) {
 | 
			
		||||
        var canvas = document.createElement('canvas');
 | 
			
		||||
        canvas.width = img.width;
 | 
			
		||||
        canvas.height = img.height;
 | 
			
		||||
        // copy the image contents to the canvas
 | 
			
		||||
        var context = canvas.getContext('2d');
 | 
			
		||||
        context.drawImage(img, 0, 0, img.width, img.height, 0, 0, img.width, img.height);
 | 
			
		||||
        return canvas;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* global Promise, Image, Blob, FileReader, atob, btoa,
 | 
			
		||||
       BlobBuilder, MSBlobBuilder, MozBlobBuilder, WebKitBlobBuilder, webkitURL */
 | 
			
		||||
    /**
 | 
			
		||||
     * 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
 | 
			
		||||
     */
 | 
			
		||||
    function createBlob(parts, properties) {
 | 
			
		||||
        parts = parts || [];
 | 
			
		||||
        properties = properties || {};
 | 
			
		||||
        if (typeof properties === 'string') {
 | 
			
		||||
            properties = { type: properties }; // infer content type
 | 
			
		||||
        }
 | 
			
		||||
        try {
 | 
			
		||||
            return new Blob(parts, properties);
 | 
			
		||||
        }
 | 
			
		||||
        catch (e) {
 | 
			
		||||
            if (e.name !== 'TypeError') {
 | 
			
		||||
                throw e;
 | 
			
		||||
            }
 | 
			
		||||
            var Builder = typeof BlobBuilder !== 'undefined'
 | 
			
		||||
                ? BlobBuilder : typeof MSBlobBuilder !== 'undefined'
 | 
			
		||||
                ? MSBlobBuilder : typeof MozBlobBuilder !== 'undefined'
 | 
			
		||||
                ? MozBlobBuilder : WebKitBlobBuilder;
 | 
			
		||||
            var builder = new Builder();
 | 
			
		||||
            for (var i = 0; i < parts.length; i += 1) {
 | 
			
		||||
                builder.append(parts[i]);
 | 
			
		||||
            }
 | 
			
		||||
            return builder.getBlob(properties.type);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    /**
 | 
			
		||||
     * 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
 | 
			
		||||
     */
 | 
			
		||||
    function createObjectURL(blob) {
 | 
			
		||||
        return (typeof URL !== 'undefined' ? URL : webkitURL).createObjectURL(blob);
 | 
			
		||||
    }
 | 
			
		||||
    /**
 | 
			
		||||
     * 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
 | 
			
		||||
     */
 | 
			
		||||
    function revokeObjectURL(url) {
 | 
			
		||||
        return (typeof URL !== 'undefined' ? URL : webkitURL).revokeObjectURL(url);
 | 
			
		||||
    }
 | 
			
		||||
    /**
 | 
			
		||||
     * 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
 | 
			
		||||
     */
 | 
			
		||||
    function blobToBinaryString(blob) {
 | 
			
		||||
        return new Promise(function (resolve, reject) {
 | 
			
		||||
            var reader = new FileReader();
 | 
			
		||||
            var hasBinaryString = typeof reader.readAsBinaryString === 'function';
 | 
			
		||||
            reader.onloadend = function () {
 | 
			
		||||
                var result = reader.result || '';
 | 
			
		||||
                if (hasBinaryString) {
 | 
			
		||||
                    return resolve(result);
 | 
			
		||||
                }
 | 
			
		||||
                resolve(arrayBufferToBinaryString(result));
 | 
			
		||||
            };
 | 
			
		||||
            reader.onerror = reject;
 | 
			
		||||
            if (hasBinaryString) {
 | 
			
		||||
                reader.readAsBinaryString(blob);
 | 
			
		||||
            }
 | 
			
		||||
            else {
 | 
			
		||||
                reader.readAsArrayBuffer(blob);
 | 
			
		||||
            }
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
    /**
 | 
			
		||||
     * 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
 | 
			
		||||
     */
 | 
			
		||||
    function base64StringToBlob(base64, type) {
 | 
			
		||||
        var parts = [binaryStringToArrayBuffer(atob(base64))];
 | 
			
		||||
        return type ? createBlob(parts, { type: type }) : createBlob(parts);
 | 
			
		||||
    }
 | 
			
		||||
    /**
 | 
			
		||||
     * 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
 | 
			
		||||
     */
 | 
			
		||||
    function binaryStringToBlob(binary, type) {
 | 
			
		||||
        return base64StringToBlob(btoa(binary), type);
 | 
			
		||||
    }
 | 
			
		||||
    /**
 | 
			
		||||
     * 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
 | 
			
		||||
     */
 | 
			
		||||
    function blobToBase64String(blob) {
 | 
			
		||||
        return blobToBinaryString(blob).then(btoa);
 | 
			
		||||
    }
 | 
			
		||||
    /**
 | 
			
		||||
     * 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
 | 
			
		||||
     */
 | 
			
		||||
    function dataURLToBlob(dataURL) {
 | 
			
		||||
        var type = dataURL.match(/data:([^;]+)/)[1];
 | 
			
		||||
        var base64 = dataURL.replace(/^[^,]+,/, '');
 | 
			
		||||
        var buff = binaryStringToArrayBuffer(atob(base64));
 | 
			
		||||
        return createBlob([buff], { type: type });
 | 
			
		||||
    }
 | 
			
		||||
    /**
 | 
			
		||||
     * 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
 | 
			
		||||
     */
 | 
			
		||||
    function blobToDataURL(blob) {
 | 
			
		||||
        return blobToBase64String(blob).then(function (base64String) {
 | 
			
		||||
            return 'data:' + blob.type + ';base64,' + base64String;
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
    /**
 | 
			
		||||
     * 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
 | 
			
		||||
     */
 | 
			
		||||
    function imgSrcToDataURL(src, type, crossOrigin, quality) {
 | 
			
		||||
        type = type || 'image/png';
 | 
			
		||||
        return loadImage(src, crossOrigin).then(imgToCanvas).then(function (canvas) {
 | 
			
		||||
            return canvas.toDataURL(type, quality);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
    /**
 | 
			
		||||
     * 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`
 | 
			
		||||
     */
 | 
			
		||||
    function canvasToBlob(canvas, type, quality) {
 | 
			
		||||
        if (typeof canvas.toBlob === 'function') {
 | 
			
		||||
            return new Promise(function (resolve) {
 | 
			
		||||
                canvas.toBlob(resolve, type, quality);
 | 
			
		||||
            });
 | 
			
		||||
        }
 | 
			
		||||
        return Promise.resolve(dataURLToBlob(canvas.toDataURL(type, quality)));
 | 
			
		||||
    }
 | 
			
		||||
    /**
 | 
			
		||||
     * 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`
 | 
			
		||||
     */
 | 
			
		||||
    function imgSrcToBlob(src, type, crossOrigin, quality) {
 | 
			
		||||
        type = type || 'image/png';
 | 
			
		||||
        return loadImage(src, crossOrigin).then(imgToCanvas).then(function (canvas) {
 | 
			
		||||
            return canvasToBlob(canvas, type, quality);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
    /**
 | 
			
		||||
     * 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
 | 
			
		||||
     */
 | 
			
		||||
    function arrayBufferToBlob(buffer, type) {
 | 
			
		||||
        return createBlob([buffer], type);
 | 
			
		||||
    }
 | 
			
		||||
    /**
 | 
			
		||||
     * 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`
 | 
			
		||||
     */
 | 
			
		||||
    function blobToArrayBuffer(blob) {
 | 
			
		||||
        return new Promise(function (resolve, reject) {
 | 
			
		||||
            var reader = new FileReader();
 | 
			
		||||
            reader.onloadend = function () {
 | 
			
		||||
                var result = reader.result || new ArrayBuffer(0);
 | 
			
		||||
                resolve(result);
 | 
			
		||||
            };
 | 
			
		||||
            reader.onerror = reject;
 | 
			
		||||
            reader.readAsArrayBuffer(blob);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
    /**
 | 
			
		||||
     * Convert an `ArrayBuffer` to a binary string.
 | 
			
		||||
     *
 | 
			
		||||
     * Example:
 | 
			
		||||
     *
 | 
			
		||||
     * ```js
 | 
			
		||||
     * var myString = blobUtil.arrayBufferToBinaryString(arrayBuff)
 | 
			
		||||
     * ```
 | 
			
		||||
     *
 | 
			
		||||
     * @param buffer - array buffer
 | 
			
		||||
     * @returns binary string
 | 
			
		||||
     */
 | 
			
		||||
    function arrayBufferToBinaryString(buffer) {
 | 
			
		||||
        var binary = '';
 | 
			
		||||
        var bytes = new Uint8Array(buffer);
 | 
			
		||||
        var length = bytes.byteLength;
 | 
			
		||||
        var i = -1;
 | 
			
		||||
        while (++i < length) {
 | 
			
		||||
            binary += String.fromCharCode(bytes[i]);
 | 
			
		||||
        }
 | 
			
		||||
        return binary;
 | 
			
		||||
    }
 | 
			
		||||
    /**
 | 
			
		||||
     * Convert a binary string to an `ArrayBuffer`.
 | 
			
		||||
     *
 | 
			
		||||
     * ```js
 | 
			
		||||
     * var myBuffer = blobUtil.binaryStringToArrayBuffer(binaryString)
 | 
			
		||||
     * ```
 | 
			
		||||
     *
 | 
			
		||||
     * @param binary - binary string
 | 
			
		||||
     * @returns array buffer
 | 
			
		||||
     */
 | 
			
		||||
    function binaryStringToArrayBuffer(binary) {
 | 
			
		||||
        var length = binary.length;
 | 
			
		||||
        var buf = new ArrayBuffer(length);
 | 
			
		||||
        var arr = new Uint8Array(buf);
 | 
			
		||||
        var i = -1;
 | 
			
		||||
        while (++i < length) {
 | 
			
		||||
            arr[i] = binary.charCodeAt(i);
 | 
			
		||||
        }
 | 
			
		||||
        return buf;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    exports.createBlob = createBlob;
 | 
			
		||||
    exports.createObjectURL = createObjectURL;
 | 
			
		||||
    exports.revokeObjectURL = revokeObjectURL;
 | 
			
		||||
    exports.blobToBinaryString = blobToBinaryString;
 | 
			
		||||
    exports.base64StringToBlob = base64StringToBlob;
 | 
			
		||||
    exports.binaryStringToBlob = binaryStringToBlob;
 | 
			
		||||
    exports.blobToBase64String = blobToBase64String;
 | 
			
		||||
    exports.dataURLToBlob = dataURLToBlob;
 | 
			
		||||
    exports.blobToDataURL = blobToDataURL;
 | 
			
		||||
    exports.imgSrcToDataURL = imgSrcToDataURL;
 | 
			
		||||
    exports.canvasToBlob = canvasToBlob;
 | 
			
		||||
    exports.imgSrcToBlob = imgSrcToBlob;
 | 
			
		||||
    exports.arrayBufferToBlob = arrayBufferToBlob;
 | 
			
		||||
    exports.blobToArrayBuffer = blobToArrayBuffer;
 | 
			
		||||
    exports.arrayBufferToBinaryString = arrayBufferToBinaryString;
 | 
			
		||||
    exports.binaryStringToArrayBuffer = binaryStringToArrayBuffer;
 | 
			
		||||
 | 
			
		||||
    Object.defineProperty(exports, '__esModule', { value: true });
 | 
			
		||||
 | 
			
		||||
})));
 | 
			
		||||
							
								
								
									
										1
									
								
								CyLukTs/lukan/node_modules/blob-util/dist/blob-util.min.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								CyLukTs/lukan/node_modules/blob-util/dist/blob-util.min.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1 @@
 | 
			
		||||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n(e.blobUtil={})}(this,function(e){"use strict";function n(e,n){return new Promise(function(r,t){var o=new Image;n&&(o.crossOrigin=n),o.onload=function(){r(o)},o.onerror=t,o.src=e})}function r(e){var n=document.createElement("canvas");return n.width=e.width,n.height=e.height,n.getContext("2d").drawImage(e,0,0,e.width,e.height,0,0,e.width,e.height),n}function t(e,n){e=e||[],"string"==typeof(n=n||{})&&(n={type:n});try{return new Blob(e,n)}catch(i){if("TypeError"!==i.name)throw i;for(var r="undefined"!=typeof BlobBuilder?BlobBuilder:"undefined"!=typeof MSBlobBuilder?MSBlobBuilder:"undefined"!=typeof MozBlobBuilder?MozBlobBuilder:WebKitBlobBuilder,t=new r,o=0;o<e.length;o+=1)t.append(e[o]);return t.getBlob(n.type)}}function o(e){return("undefined"!=typeof URL?URL:webkitURL).createObjectURL(e)}function i(e){return("undefined"!=typeof URL?URL:webkitURL).revokeObjectURL(e)}function u(e){return new Promise(function(n,r){var t=new FileReader,o="function"==typeof t.readAsBinaryString;t.onloadend=function(){var e=t.result||"";if(o)return n(e);n(h(e))},t.onerror=r,o?t.readAsBinaryString(e):t.readAsArrayBuffer(e)})}function a(e,n){var r=[p(atob(e))];return n?t(r,{type:n}):t(r)}function f(e,n){return a(btoa(e),n)}function c(e){return u(e).then(btoa)}function d(e){var n=e.match(/data:([^;]+)/)[1],r=e.replace(/^[^,]+,/,"");return t([p(atob(r))],{type:n})}function b(e){return c(e).then(function(n){return"data:"+e.type+";base64,"+n})}function l(e,t,o,i){return t=t||"image/png",n(e,o).then(r).then(function(e){return e.toDataURL(t,i)})}function B(e,n,r){return"function"==typeof e.toBlob?new Promise(function(t){e.toBlob(t,n,r)}):Promise.resolve(d(e.toDataURL(n,r)))}function y(e,t,o,i){return t=t||"image/png",n(e,o).then(r).then(function(e){return B(e,t,i)})}function g(e,n){return t([e],n)}function s(e){return new Promise(function(n,r){var t=new FileReader;t.onloadend=function(){var e=t.result||new ArrayBuffer(0);n(e)},t.onerror=r,t.readAsArrayBuffer(e)})}function h(e){for(var n="",r=new Uint8Array(e),t=r.byteLength,o=-1;++o<t;)n+=String.fromCharCode(r[o]);return n}function p(e){for(var n=e.length,r=new ArrayBuffer(n),t=new Uint8Array(r),o=-1;++o<n;)t[o]=e.charCodeAt(o);return r}e.createBlob=t,e.createObjectURL=o,e.revokeObjectURL=i,e.blobToBinaryString=u,e.base64StringToBlob=a,e.binaryStringToBlob=f,e.blobToBase64String=c,e.dataURLToBlob=d,e.blobToDataURL=b,e.imgSrcToDataURL=l,e.canvasToBlob=B,e.imgSrcToBlob=y,e.arrayBufferToBlob=g,e.blobToArrayBuffer=s,e.arrayBufferToBinaryString=h,e.binaryStringToArrayBuffer=p,Object.defineProperty(e,"__esModule",{value:!0})});
 | 
			
		||||
							
								
								
									
										69
									
								
								CyLukTs/lukan/node_modules/blob-util/package.json
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										69
									
								
								CyLukTs/lukan/node_modules/blob-util/package.json
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,69 @@
 | 
			
		||||
{
 | 
			
		||||
  "name": "blob-util",
 | 
			
		||||
  "version": "2.0.2",
 | 
			
		||||
  "description": "Utilities for working with Blob objects in the browser",
 | 
			
		||||
  "main": "dist/blob-util.cjs.js",
 | 
			
		||||
  "module": "dist/blob-util.es.js",
 | 
			
		||||
  "types": "dist/blob-util.d.ts",
 | 
			
		||||
  "repository": {
 | 
			
		||||
    "type": "git",
 | 
			
		||||
    "url": "git://github.com/nolanlawson/blob-util.git"
 | 
			
		||||
  },
 | 
			
		||||
  "keywords": [
 | 
			
		||||
    "blob",
 | 
			
		||||
    "blobs",
 | 
			
		||||
    "binary",
 | 
			
		||||
    "util",
 | 
			
		||||
    "utils"
 | 
			
		||||
  ],
 | 
			
		||||
  "author": "Nolan Lawson <nolan.lawson@gmail.com>",
 | 
			
		||||
  "license": "Apache-2.0",
 | 
			
		||||
  "bugs": {
 | 
			
		||||
    "url": "https://github.com/nolanlawson/blob-util/issues"
 | 
			
		||||
  },
 | 
			
		||||
  "scripts": {
 | 
			
		||||
    "lint": "standard test/*js bin/*js && tslint src/*ts",
 | 
			
		||||
    "test": "npm run build && npm run lint && zuul --no-coverage ./test/test.js",
 | 
			
		||||
    "test-local": "npm run build && zuul ./test/test.js --local 9000 --no-coverage",
 | 
			
		||||
    "clean": "rimraf dist lib && mkdirp dist lib",
 | 
			
		||||
    "prepublish": "npm run build",
 | 
			
		||||
    "build": "run-s clean build-ts build-js min",
 | 
			
		||||
    "build-ts": "tsc src/blob-util.ts --target ES6 --module es2015 --outDir lib -d && cpy lib/blob-util.d.ts dist/",
 | 
			
		||||
    "build-js": "run-p build-es build-cjs build-umd && rimraf lib",
 | 
			
		||||
    "build-es": "rollup -i lib/blob-util.js -f es -o dist/blob-util.es.js",
 | 
			
		||||
    "build-cjs": "rollup -i lib/blob-util.js -f cjs -o dist/blob-util.cjs.js",
 | 
			
		||||
    "build-umd": "rollup -i lib/blob-util.js -f umd -n blobUtil -o dist/blob-util.js",
 | 
			
		||||
    "min": "uglifyjs dist/blob-util.js -mc > dist/blob-util.min.js",
 | 
			
		||||
    "doc": "run-s cleanup-doc gen-doc gen-readme cleanup-doc",
 | 
			
		||||
    "gen-doc": "typedoc --out docs-tmp --target ES6 --theme markdown --mdHideSources --excludePrivate --exclude private.ts src",
 | 
			
		||||
    "gen-readme": "node bin/write-docs-to-readme.js",
 | 
			
		||||
    "cleanup-doc": "rimraf docs-tmp"
 | 
			
		||||
  },
 | 
			
		||||
  "devDependencies": {
 | 
			
		||||
    "bundle-collapser": "^1.1.4",
 | 
			
		||||
    "chai": "~1.8.1",
 | 
			
		||||
    "chai-as-promised": "~4.1.0",
 | 
			
		||||
    "cpy-cli": "^1.0.1",
 | 
			
		||||
    "istanbul": "^0.2.7",
 | 
			
		||||
    "mkdirp": "^0.5.0",
 | 
			
		||||
    "mocha": "~1.18",
 | 
			
		||||
    "native-or-lie": "1.0.2",
 | 
			
		||||
    "npm-run-all": "^4.1.3",
 | 
			
		||||
    "pify": "^3.0.0",
 | 
			
		||||
    "request": "^2.36.0",
 | 
			
		||||
    "rimraf": "^2.6.2",
 | 
			
		||||
    "rollup": "^0.59.1",
 | 
			
		||||
    "standard": "^11.0.1",
 | 
			
		||||
    "tslint": "^5.10.0",
 | 
			
		||||
    "tslint-config-standard": "^7.0.0",
 | 
			
		||||
    "typedoc": "^0.11.1",
 | 
			
		||||
    "typedoc-plugin-markdown": "^1.1.11",
 | 
			
		||||
    "typescript": "^2.8.3",
 | 
			
		||||
    "uglify-js": "^2.4.13",
 | 
			
		||||
    "zuul": "^3.10.1",
 | 
			
		||||
    "zuul-ngrok": "nolanlawson/zuul-ngrok#patch-1"
 | 
			
		||||
  },
 | 
			
		||||
  "files": [
 | 
			
		||||
    "dist"
 | 
			
		||||
  ]
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user