MCPcopy Create free account
hub / github.com/processing/p5.js / downloadFile

Function downloadFile

src/io/utilities.js:1–18  ·  view source on GitHub ↗
(data, fName, extension)

Source from the content-addressed store, hash-verified

1function downloadFile(data, fName, extension) {
2 const fx = _checkFileExtension(fName, extension);
3 const filename = fx[0];
4 let saveData = data;
5
6 if (!(saveData instanceof Blob)) {
7 saveData = new Blob([data]);
8 }
9
10 if(document){
11 const url = URL.createObjectURL(saveData);
12 const link = document.createElement('a');
13 link.href = url;
14 link.download = filename;
15 link.click();
16 URL.revokeObjectURL(url);
17 }
18}
19
20function _checkFileExtension(filename, extension) {
21 if (!extension || extension === true || extension === 'true') {

Callers 4

saveMethod · 0.90
encodeAndDownloadGifFunction · 0.90
saveObjMethod · 0.90
saveStlMethod · 0.90

Calls 1

_checkFileExtensionFunction · 0.85

Tested by

no test coverage detected