diff options
author | RaindropsSys <contact@minteck.org> | 2023-04-04 19:07:33 +0200 |
---|---|---|
committer | RaindropsSys <contact@minteck.org> | 2023-04-04 19:07:33 +0200 |
commit | b9aca19cccf9fd85a05d2ae32846b5b4f25a4dc1 (patch) | |
tree | 1ecb5f1c27f159bb175ecded73d4235fcfb4b5ae /includes/external/addressbook/node_modules/axios/lib/helpers/fromDataURI.js | |
parent | 704e1c22efe6056b0fc2f59b2766f47e1c8d71cc (diff) | |
download | pluralconnect-b9aca19cccf9fd85a05d2ae32846b5b4f25a4dc1.tar.gz pluralconnect-b9aca19cccf9fd85a05d2ae32846b5b4f25a4dc1.tar.bz2 pluralconnect-b9aca19cccf9fd85a05d2ae32846b5b4f25a4dc1.zip |
Added 147 files (automated)
Diffstat (limited to 'includes/external/addressbook/node_modules/axios/lib/helpers/fromDataURI.js')
-rw-r--r-- | includes/external/addressbook/node_modules/axios/lib/helpers/fromDataURI.js | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/includes/external/addressbook/node_modules/axios/lib/helpers/fromDataURI.js b/includes/external/addressbook/node_modules/axios/lib/helpers/fromDataURI.js new file mode 100644 index 0000000..eb71d3f --- /dev/null +++ b/includes/external/addressbook/node_modules/axios/lib/helpers/fromDataURI.js @@ -0,0 +1,53 @@ +'use strict'; + +import AxiosError from '../core/AxiosError.js'; +import parseProtocol from './parseProtocol.js'; +import platform from '../platform/index.js'; + +const DATA_URL_PATTERN = /^(?:([^;]+);)?(?:[^;]+;)?(base64|),([\s\S]*)$/; + +/** + * Parse data uri to a Buffer or Blob + * + * @param {String} uri + * @param {?Boolean} asBlob + * @param {?Object} options + * @param {?Function} options.Blob + * + * @returns {Buffer|Blob} + */ +export default function fromDataURI(uri, asBlob, options) { + const _Blob = options && options.Blob || platform.classes.Blob; + const protocol = parseProtocol(uri); + + if (asBlob === undefined && _Blob) { + asBlob = true; + } + + if (protocol === 'data') { + uri = protocol.length ? uri.slice(protocol.length + 1) : uri; + + const match = DATA_URL_PATTERN.exec(uri); + + if (!match) { + throw new AxiosError('Invalid URL', AxiosError.ERR_INVALID_URL); + } + + const mime = match[1]; + const isBase64 = match[2]; + const body = match[3]; + const buffer = Buffer.from(decodeURIComponent(body), isBase64 ? 'base64' : 'utf8'); + + if (asBlob) { + if (!_Blob) { + throw new AxiosError('Blob is not supported', AxiosError.ERR_NOT_SUPPORT); + } + + return new _Blob([buffer], {type: mime}); + } + + return buffer; + } + + throw new AxiosError('Unsupported protocol ' + protocol, AxiosError.ERR_NOT_SUPPORT); +} |