MCPcopy Index your code
hub / github.com/adobe/react-spectrum / download

Function download

scripts/compareSize.js:87–125  ·  view source on GitHub ↗
(url, dest)

Source from the content-addressed store, hash-verified

85
86// Resolve only so that we can attempt a hardcoded link download if the commit one fails. TODO: revert back to reject when we get some intial data from a publish.
87function download(url, dest) {
88 return new Promise((resolve, reject) => {
89 // Check file does not exist yet before hitting network
90 fs.access(dest, fs.constants.F_OK, err => {
91 if (err === null) {
92 console.error(`File already exists at ${dest}`);
93 resolve();
94 }
95 let request = https.get(url, response => {
96 if (response.statusCode === 200) {
97 const file = fs.createWriteStream(dest, {flags: 'wx'});
98 file.on('finish', () => resolve());
99 file.on('error', err => {
100 file.close();
101 if (err.code === 'EEXIST') {
102 console.error(`File was created during the request call at ${dest}`);
103 resolve();
104 } else {
105 // Delete temp file
106 fs.unlink(dest, () => {
107 console.error(err.message);
108 resolve();
109 });
110 }
111 });
112 response.pipe(file);
113 } else {
114 console.error(`Server responded with ${response.statusCode}: ${response.statusMessage}`);
115 resolve();
116 }
117 });
118
119 request.on('error', err => {
120 console.error(err);
121 resolve();
122 });
123 });
124 });
125}

Callers 1

compareBuildAppSizeFunction · 0.85

Calls 2

closeMethod · 0.65
resolveFunction · 0.50

Tested by

no test coverage detected