Back | Home
الـ Path الحالي: /home/picotech/domains/instantly.picotech.app/public_html/public/uploads/../uploads/../../../../instantly.picotech.app/homes/../../wa.picotech.app/public_html/node_modules/path-exists/../duplexify/./../@protobufjs/../cheerio/../@socket.io/../ee-first/../path-exists/../dotenv/../y18n/../methods/../../node_modules/validator/../negotiator/../base64id/../validator/../axios/lib/helpers
الملفات الموجودة في هذا الـ Path:
.
..
AxiosTransformStream.js
AxiosURLSearchParams.js
HttpStatusCode.js
README.md
ZlibHeaderTransformStream.js
bind.js
buildURL.js
callbackify.js
combineURLs.js
cookies.js
deprecatedMethod.js
formDataToJSON.js
formDataToStream.js
fromDataURI.js
isAbsoluteURL.js
isAxiosError.js
isURLSameOrigin.js
null.js
parseHeaders.js
parseProtocol.js
readBlob.js
speedometer.js
spread.js
throttle.js
toFormData.js
toURLEncodedForm.js
validator.js

مشاهدة ملف: fromDataURI.js

'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);
}