MCPcopy Create free account
hub / github.com/cutupdev/Solana-Volume-Bot / saveDataToFile

Function saveDataToFile

utils/utils.ts:50–79  ·  view source on GitHub ↗
(newData: Data[], filePath: string = "data.json")

Source from the content-addressed store, hash-verified

48
49
50export const saveDataToFile = (newData: Data[], filePath: string = "data.json") => {
51 try {
52 let existingData: Data[] = [];
53
54 // Check if the file exists
55 if (fs.existsSync(filePath)) {
56 // If the file exists, read its content
57 const fileContent = fs.readFileSync(filePath, 'utf-8');
58 existingData = JSON.parse(fileContent);
59 }
60
61 // Add the new data to the existing array
62 existingData.push(...newData);
63
64 // Write the updated data back to the file
65 fs.writeFileSync(filePath, JSON.stringify(existingData, null, 2));
66
67 } catch (error) {
68 try {
69 if (fs.existsSync(filePath)) {
70 fs.unlinkSync(filePath);
71 console.log(`File ${filePath} deleted and create new file.`);
72 }
73 fs.writeFileSync(filePath, JSON.stringify(newData, null, 2));
74 console.log("File is saved successfully.")
75 } catch (error) {
76 console.log('Error saving data to JSON file:', error);
77 }
78 }
79};
80
81export const sleep = async (ms: number) => {
82 await new Promise((resolve) => setTimeout(resolve, ms))

Callers 2

distributeSolFunction · 0.90
distributeSolAndTokenFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected