lib/actions/convert-data-url.js
function saveAsFile(editor, data, range) {
	return new Promise((resolve, reject) => {
		const fileName = atom.getCurrentWindow().showSaveDialog();
		if (!fileName) {
			return reject(new Error('User cancelled file dialog'));
		}

		fs.writeFile(fileName, Buffer.from(data, 'base64'), err => {
			if (err) {
				return reject(err);
			}

			const editorPath = editor.getPath();
			let displayPath = editorPath
				? path.relative(editorPath, fileName)
				: `file://${fileName}`;

			editor.transact(() => {
				// Convert Windows path separators to Unix
				editor.setTextInBufferRange(range, displayPath.replace(/\\+/g, '/'));
			});

			resolve(fileName);
		});
	});
}
function saveAsFile(editor, data, range) {
	return new Promise((resolve, reject) => {
		const fileName = atom.getCurrentWindow().showSaveDialog();
		if (!fileName) {
			return reject(new Error('User cancelled file dialog'));
		}

		fs.writeFile(fileName, Buffer.from(data, 'base64'), err => {
			if (err) {
				return reject(err);
			}

			const editorPath = editor.getPath();
			let displayPath = editorPath
				? path.relative(editorPath, fileName)
				: `file://${fileName}`;

			editor.transact(() => {
				// Convert Windows path separators to Unix
				editor.setTextInBufferRange(range, displayPath.replace(/\\+/g, '/'));
			});

			resolve(fileName);
		});
	});
}
function saveAsFile ( editor , data , range ) { return new Promise ( ( resolve , reject ) => { const fileName = atom . getCurrentWindow ( ) . showSaveDialog ( ) ; if ( ! fileName ) { return reject ( new Error ( 'User cancelled file dialog' ) ) ; } fs . writeFile ( fileName , Buffer . from ( data , 'base64' ) , err => { if ( err ) { return reject ( err ) ; } const editorPath = editor . getPath ( ) ; let displayPath = editorPath ? path . relative ( editorPath , fileName ) : ` ${ fileName } ` ; editor . transact ( ( ) => { // Convert Windows path separators to Unix editor . setTextInBufferRange ( range , displayPath . replace ( / \\+ / g , '/' ) ) ; } ) ; resolve ( fileName ) ; } ) ; } ) ; }
Saves given base64-encoded string as file on file system
@param  {TextEditor} editor
@param  {String}     data   Base64-encoded file
@param  {Range}      range  Editor’s replacement where saved file URL should
be written
@return {Promise}
Saves given base64 - encoded string as file on file system