From 8dd111d680900d720c8ca8553a0052263e9c8477 Mon Sep 17 00:00:00 2001 From: "Luiz F. Picolo" Date: Mon, 19 Jun 2023 11:01:35 -0400 Subject: [PATCH] =?UTF-8?q?Adicionado=20m=C3=A9todo=20para=20finalizar=20s?= =?UTF-8?q?ection=20ipfs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- retrive.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) 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();