MCPcopy Create free account
hub / github.com/observablehq/framework / findArchive

Method findArchive

src/loader.ts:191–232  ·  view source on GitHub ↗
(targetPath: string)

Source from the content-addressed store, hash-verified

189 // - /[param].zip.js
190 // - /[param].tgz.js
191 private findArchive(targetPath: string): Loader | undefined {
192 const exts = this.getArchiveExtensions();
193 for (let dir = dirname(targetPath), parent: string; (parent = dirname(dir)) !== dir; dir = parent) {
194 const found = route(this.root, dir, exts);
195 if (!found) continue;
196 const {path, params, ext: fext} = found;
197 const inflatePath = targetPath.slice(dir.length + 1); // file.jpeg
198 if (extractors.has(fext)) {
199 const Extractor = extractors.get(fext)!;
200 return new Extractor({
201 preload: async () => path, // /path/to.zip
202 inflatePath,
203 path,
204 params,
205 root: this.root,
206 targetPath // /path/to/file.jpg
207 });
208 }
209 const iext = extname(fext);
210 const commandPath = join(this.root, path);
211 const [command, ...args] = this.interpreters.get(iext)!;
212 if (command != null) args.push(commandPath);
213 const eext = fext.slice(0, -iext.length); // .zip
214 const loader = new CommandLoader({
215 command: command ?? commandPath,
216 args: params ? args.concat(defineParams(params)) : args,
217 path,
218 params,
219 root: this.root,
220 targetPath: dir + eext // /path/to.zip
221 });
222 const Extractor = extractors.get(eext)!;
223 return new Extractor({
224 preload: async (options, effects) => loader.load(options, effects), // /path/to.zip.js
225 inflatePath,
226 path: loader.path,
227 params,
228 root: this.root,
229 targetPath
230 });
231 }
232 }
233
234 // .zip, .tar, .tgz, .zip.js, .zip.py, etc.
235 getArchiveExtensions(): string[] {

Callers 1

findMethod · 0.95

Calls 4

getArchiveExtensionsMethod · 0.95
routeFunction · 0.85
defineParamsFunction · 0.85
loadMethod · 0.65

Tested by

no test coverage detected