MCPcopy Index your code
hub / github.com/GooseMod/OpenAsar / downloadModule

Function downloadModule

src/updater/moduleUpdater.js:131–170  ·  view source on GitHub ↗
(name, ver)

Source from the content-addressed store, hash-verified

129};
130
131const downloadModule = async (name, ver) => {
132 downloading.total++;
133
134 const path = join(downloadPath, name + '-' + ver + '.zip');
135 const file = fs.createWriteStream(path);
136
137 // log('Modules', 'Downloading', `${name}@${ver}`);
138
139 let success, total, cur = 0;
140 const res = await redirs(baseUrl + '/' + name + '/' + ver + qs);
141 success = res.statusCode === 200;
142 total = parseInt(res.headers['content-length'] ?? 1, 10);
143
144 res.pipe(file);
145
146 res.on('data', c => {
147 cur += c.length;
148
149 events.emit('downloading-module', { name, cur, total });
150 });
151
152 await new Promise((res) => file.on('close', res));
153
154 if (success) commitManifest();
155 else downloading.fail++;
156
157 events.emit('downloaded-module', {
158 name
159 });
160
161 downloading.done++;
162
163 if (downloading.done === downloading.total) {
164 events.emit('downloaded', {
165 failed: downloading.fail
166 });
167 }
168
169 installModule(name, ver, path);
170};
171
172const installModule = async (name, ver, path) => {
173 installing.total++;

Callers 2

checkModulesFunction · 0.85
moduleUpdater.jsFile · 0.85

Calls 3

commitManifestFunction · 0.85
installModuleFunction · 0.85
redirsFunction · 0.70

Tested by

no test coverage detected