How to use data-urls - 7 common examples

To help you get started, we’ve selected a few data-urls examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github beakerbrowser / beaker / app / background-process / ui / downloads.js View on Github external
item.on('done', (e, state) => {
      // inform users of error conditions
      var overrides = false
      if (state === 'interrupted') {
        // this can sometimes happen because the link is a data: URI
        // in that case, we can manually parse and save it
        if (item.getURL().startsWith('data:')) {
          let parsed = parseDataURL(item.getURL())
          if (parsed) {
            fs.writeFileSync(filePath, parsed.body)
            overrides = {
              state: 'completed',
              receivedBytes: parsed.body.length,
              totalBytes: parsed.body.length
            }
          }
        }
        if (!overrides) {
          dialog.showErrorBox('Download error', `The download of ${item.getFilename()} was interrupted`)
        }
      }

      downloadsEvents.emit('done', toJSON(item, overrides))
github beakerbrowser / beaker / app / background-process / ui / downloads.js View on Github external
item.on('done', (e, state) => {
      // inform users of error conditions
      var overrides = false
      if (state === 'interrupted') {
        // this can sometimes happen because the link is a data: URI
        // in that case, we can manually parse and save it
        if (item.getURL().startsWith('data:')) {
          let parsed = parseDataURL(item.getURL())
          if (parsed) {
            fs.writeFileSync(item.getSavePath(), parsed.body)
            overrides = {
              state: 'completed',
              receivedBytes: parsed.body.length,
              totalBytes: parsed.body.length
            }
          }
        }
        if (!overrides) {
          dialog.showErrorBox('Download error', `The download of ${item.getFilename()} was interrupted`)
        }
      }

      downloadsEvents.emit('done', toJSON(item, overrides))
github jsdom / jsdom / lib / jsdom / browser / resources / resource-loader.js View on Github external
fetch(urlString, options = {}) {
    const url = parseURL(urlString);

    if (!url) {
      return Promise.reject(new Error(`Tried to fetch invalid URL ${urlString}`));
    }

    switch (url.scheme) {
      case "data": {
        return Promise.resolve(dataURLFromRecord(url).body);
      }

      case "http":
      case "https": {
        const requestOptions = this._getRequestOptions(options);
        return request(urlString, requestOptions);
      }

      case "file": {
        // TODO: Improve the URL => file algorithm. See https://github.com/jsdom/jsdom/pull/2279#discussion_r199977987
        const filePath = urlString
          .replace(/^file:\/\//, "")
          .replace(/^\/([a-z]):\//i, "$1:/")
          .replace(/%20/g, " ");

        return this._readFile(filePath);
github liferay / liferay-js-toolkit / packages / liferay-npm-bundler / src / util.js View on Github external
const annotation = fileContent.toString().substring(offset);

	let matches = annotation.match(/\/\/# sourceMappingURL=(.*)/);
	if (!matches) {
		matches = annotation.match(/\/\*# sourceMappingURL=(.*) \*\//);

		if (!matches) {
			return null;
		}
	}

	const url = matches[1];

	if (url.indexOf('data:') == 0) {
		const parsedData = parseDataURL(url);

		if (parsedData) {
			const {body, mimeType} = parsedData;

			if (mimeType.toString() === 'application/json') {
				return JSON.parse(body.toString());
			}
		}
	} else {
		const sourceMapFile = path.normalize(
			path.join(path.dirname(filePath), url)
		);

		try {
			return readJsonSync(sourceMapFile);
		} catch (err) {
github plotly / falcon / backend / persistent / datastores / csv.js View on Github external
function connect(connection) {
    const url = connection.database;

    const size = getAvailableSize();
    if (size === -1) {
        throw new Error('Out of memory');
    }

    let getCSVFile;
    if (url.startsWith('data:')) {
        if (size !== 0 && url.length > size) {
            throw new Error('Out of memory');
        }

        const dataURL = parseDataURL(url);
        const encoding = labelToName(dataURL.mimeType.parameters.get('charset'));
        const body = decode(dataURL.body, encoding);

        getCSVFile = Promise.resolve(body);
    } else {
        getCSVFile = fetch(url, {size: size}).then(res => res.text());
    }

    return getCSVFile.then(body => {
        increaseUsedSize(body.length);

        return new Promise(function(resolve) {
            papa.parse(body, {
                download: false,
                dynamicTyping: true,
                skipEmptyLines: true,
github liferay / liferay-js-toolkit / packages / liferay-npm-bundler / src / steps / transform.js View on Github external
const annotation = fileContent.toString().substring(offset);

	let matches = annotation.match(/\/\/# sourceMappingURL=(.*)/);
	if (!matches) {
		matches = annotation.match(/\/\*# sourceMappingURL=(.*) \*\//);

		if (!matches) {
			return null;
		}
	}

	const url = matches[1];

	if (url.indexOf('data:') == 0) {
		const parsedData = parseDataURL(url);

		if (parsedData) {
			const {body, mimeType} = parsedData;

			if (mimeType.toString() === 'application/json') {
				return JSON.parse(body.toString());
			}
		}
	} else {
		const sourceMapFile = path.normalize(
			path.join(path.dirname(filePath), url)
		);

		try {
			return readJsonSync(sourceMapFile);
		} catch (err) {

data-urls

Parses data: URLs

MIT
Latest version published 5 months ago

Package Health Score

78 / 100
Full package analysis

Popular data-urls functions