MCPcopy Create free account
hub / github.com/markmap/markmap / downloadAsset

Function downloadAsset

packages/markmap-cli/src/fetch-assets.ts:70–92  ·  view source on GitHub ↗
(
  fullPath: string,
  resolveUrl: () => Promise<string>,
)

Source from the content-addressed store, hash-verified

68}
69
70async function downloadAsset(
71 fullPath: string,
72 resolveUrl: () => Promise<string>,
73) {
74 try {
75 const result = await stat(fullPath);
76 // Skip existing files
77 if (result.isFile()) return;
78 } catch {
79 // ignore
80 }
81 const url = await resolveUrl();
82 let body: ReadableStream;
83 if (url.startsWith('/')) {
84 body = createStreamBody(createReadStream(url));
85 } else {
86 const res = await fetch(url);
87 if (!res.ok || !res.body) throw new Error(`Failed to download: ${url}`);
88 body = res.body;
89 }
90 await mkdir(dirname(fullPath), { recursive: true });
91 await pipeline(body, createWriteStream(fullPath));
92}
93
94async function main() {
95 await fetchAssets({ verbose: true });

Callers 1

fetchAssetsFunction · 0.85

Calls 1

createStreamBodyFunction · 0.90

Tested by

no test coverage detected