diff --git a/retrive.js b/retrive.js index 1d78cf1..ce3d285 100644 --- a/retrive.js +++ b/retrive.js @@ -22,16 +22,24 @@ class IPFSFileManager { const fileData = Buffer.concat(chunks); // Save the file data to a local file - const filePath = `./retrievedFile.txt`; + const filePath = `./retrievedFile.pdf`; writeFileSync(filePath, fileData); - + + this.closeIPFS(); console.log('File retrieved from IPFS and saved as:', filePath); } catch (error) { console.error('Failed to retrieve the file from IPFS', error); } } + + async closeIPFS() { + if (this.node) { + await this.node.stop(); + console.log('IPFS node connection closed'); + } + } } -const cid = 'QmQzHxipWRHw8xmR8nwbiYasxQzKMh7rdwYwDxpyuoS9jX'; // Replace with the CID of the file you want to retrieve +const cid = 'QmQgGxzWnzjCfouxRiozBiEG3wcsuJGWjtHjv3wurVbJ9s'; // Replace with the CID of the file you want to retrieve const ipfsFileManager = new IPFSFileManager(cid); ipfsFileManager.retrieveFileFromIPFS();