From a2bc9748a0fb093050bc724e8b48bdad7e1a3684 Mon Sep 17 00:00:00 2001 From: "Luiz F. Picolo" Date: Tue, 20 Jun 2023 18:36:02 -0400 Subject: [PATCH] Update README with installation instructions --- README.md | 48 ++++++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 5f1da29..0a13ebb 100644 --- a/README.md +++ b/README.md @@ -2,51 +2,55 @@ This repository contains JavaScript code to interact with IPFS (InterPlanetary File System). It provides functionalities to add and retrieve files from IPFS. -## Adding a File to IPFS +## Installation + +Before running the code, make sure you have Node.js installed in your development environment. You can download it from the official Node.js website: [https://nodejs.org](https://nodejs.org) + +To install the necessary dependencies, navigate to the project directory and run the following command: + +```bash +npm install +``` + +This will install the required packages specified in the `package.json` file. + +## Usage + +### Adding a File to IPFS To add a file to IPFS, use the following code: ```javascript -import { create } from 'ipfs'; -import { writeFile } from 'fs/promises'; +import IPFSFileUploader from './IPFSFileUploader.js'; -class IPFSFileManager { - // ... -} +const ipfsUploader = new IPFSFileUploader(); -const ipfsFileManager = new IPFSFileManager(); - -const filePath = './file.txt'; -ipfsFileManager.addFileToIPFS(filePath); +const filePath = './file.txt'; // Replace with the path of the file you want to add to IPFS +ipfsUploader.uploadFileToIPFS(filePath); ``` Make sure to replace `filePath` with the path of the file you want to add to IPFS. -## Retrieving a File from IPFS +### Retrieving a File from IPFS To retrieve a file from IPFS, use the following code: ```javascript -import { create } from 'ipfs'; -import { writeFile } from 'fs/promises'; -import { fileTypeFromBuffer } from 'file-type'; +import IPFSFileRetriever from './IPFSFileRetriever.js'; -class IPFSFileManager { - // ... -} - -const ipfsFileManager = new IPFSFileManager(); +const ipfsRetriever = new IPFSFileRetriever(); const cid = 'QmQgGxzWnzjCfouxRiozBiEG3wcsuJGWjtHjv3wurVbJ9s'; // Replace with the CID of the file you want to retrieve const filepath = './retrievedFile'; // Specify the file path without the extension -ipfsFileManager.retrieveFileFromIPFS(cid, filepath); +ipfsRetriever.retrieveFileFromIPFS(cid, filepath); ``` Make sure to replace `cid` with the CID of the file you want to retrieve from IPFS. ## Notes -- Make sure you have Node.js installed in your development environment. -- Install the necessary dependencies before running the code. You can use npm or yarn to install the dependencies specified in the `package.json` file. +- The code depends on the IPFS package for Node.js. It will be installed automatically when you run `npm install`. +- The code uses the `fs/promises` module for file operations, which is available in Node.js version 14.0.0 and above. +- Additional dependencies such as `file-type` may be required for file type determination. They will also be installed automatically. Feel free to explore and modify the code according to your needs. \ No newline at end of file