How to use the data-urls function in data-urls

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 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 6 months ago

Package Health Score

78 / 100
Full package analysis

Popular data-urls functions