MCPcopy Create free account
hub / github.com/subquery/subql / saveFile

Function saveFile

packages/node-core/src/utils/project.ts:193–204  ·  view source on GitHub ↗
(reader: Reader, root: string, file: string, data: string, ext = 'js')

Source from the content-addressed store, hash-verified

191}
192
193export async function saveFile(reader: Reader, root: string, file: string, data: string, ext = 'js'): Promise<string> {
194 if (!(reader instanceof IPFSReader || reader instanceof GithubReader)) {
195 throw new Error('Only IPFS and Github readers can save remote files');
196 }
197 const resolved = path.resolve(root, file.replace('ipfs://', ''));
198 const outputPath = ext ? `${resolved}.${ext}` : resolved;
199 if (fs.existsSync(outputPath)) {
200 return outputPath;
201 }
202 await fs.promises.writeFile(outputPath, data);
203 return outputPath;
204}
205
206export async function loadDataSourceScript(reader: Reader, file?: string): Promise<string> {
207 let entry = file;

Callers 3

getChainTypesFunction · 0.90
updateDataSourcesEntryFunction · 0.85
fetchAndSaveFileFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected