Adicionado método para finalizar section ipfs
This commit is contained in:
parent
3a570d232f
commit
8dd111d680
12
retrive.js
12
retrive.js
@ -22,16 +22,24 @@ class IPFSFileManager {
|
|||||||
const fileData = Buffer.concat(chunks);
|
const fileData = Buffer.concat(chunks);
|
||||||
|
|
||||||
// Save the file data to a local file
|
// Save the file data to a local file
|
||||||
const filePath = `./retrievedFile.txt`;
|
const filePath = `./retrievedFile.pdf`;
|
||||||
writeFileSync(filePath, fileData);
|
writeFileSync(filePath, fileData);
|
||||||
|
|
||||||
|
this.closeIPFS();
|
||||||
console.log('File retrieved from IPFS and saved as:', filePath);
|
console.log('File retrieved from IPFS and saved as:', filePath);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to retrieve the file from IPFS', 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);
|
const ipfsFileManager = new IPFSFileManager(cid);
|
||||||
ipfsFileManager.retrieveFileFromIPFS();
|
ipfsFileManager.retrieveFileFromIPFS();
|
||||||
|
Loading…
Reference in New Issue
Block a user