Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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))
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))
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);
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) {
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,
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) {