@moibitjs/core

The Core module of moibitjs to interact with MoiBit off-chain Storage platform


Keywords
off-chain, storage, moibit, js, core, sdk, decentralized-storage, immutability, javascript
License
GPL-3.0
Install
npm install @moibitjs/core@1.0.0

Documentation

MoiBit banner logo

@moibitjs/core

npm version Chat on Slack Chat on Telegram Follow us on Twitter

Core module of MoiBitJS to interact with MoiBit off-chain decentralized storage platform.

This library will help Authorized Dapp Developers to store , read , delete , pin , unpin , detail the file(s) using MoiBit as their storage platform

Click here to get authorized in MoiBit. You will be getting API_KEY , API_SECRET , URL after successful signup.

Install

Using npm:

npm install --save @moibitjs/core

Getting started

(async  => {
	//import moibit core sdk
	import  MoiBit  from  '@moibitjs/core'
	//create moibit instance
	const  files = new  MoiBit(
		// the url you got after signing up to moibit
		'<your-url>', {
		'API_KEY' : '<your-api-key>', // the api key you got after signing up to moibit
		'API_SECRET' : '<your-api-secret>'  // the api key you got after signing up to moibit
	});
	console.log(await files.storageDetails('GB'));
})()

Functions


new MoiBit(url,accessToken)

This constructor is to wrap files module with url and access token , so that you don't need to send access token in every call. However authentication will be happen for every call.

  • url the url you got after signup
  • accessToken is an object with API_KEY and API_SECRET as keys
let files = new MoiBit(<YOUR_URL>,{
	API_KEY : '<YOUR_API_KEY>' ,
	API_SECRET : '<YOUR_API_SECRET>'
});

files.add(file,path,options)

Adds file of any type to MoiBit and returns back multi-hash of the file.

  • file can be window file object or stream

  • path is an absolute path in your files directory at which you want the file to be inserted.

  • options

    • createFolders is a boolean value which specifies to create a folder/not if it is not existing , that was mentioned in above path attribute (default : true)

    • pinVersion is a boolean value which tells to pin the file while adding.(default : false)

await  files.add(fileObject,'parent1/folder2/file3.txt'});

files.read(path,responseType)

Returns file in mentioned response type from its file name.

File modified off-chain

  • path is an absolute path

  • responseType can be anything among

    • arraybuffer , document , json , text , stream

    • blob - browser only

await files.read('parent1/folder2/file3.txt','blob');

files.readFromHash(hash,responseType)

Returns file in mentioned response type from its hash.

  • hash is multihash of the file

  • responseType can be anything among

    • arraybuffer , document , json , text , stream

    • blob - browser only

await files.readFromHash('Qmbg......','json');

files.list(path)

Returns array of files within the folder mentioned.

  • path is absolute path of the folder, if path is undefined or not mentioned will return all the files in your root folder.
await files.list('parent1/folder2');

files.remove(path)

Removes the file from MoiBit and returns back the acknowledgement

  • path is absolute path of the file
await files.remove('parent1/folder2/file2.txt');

files.pin(options)

Pins the file in MoiBit , so that garbage Collector won't collect the file even though the file was not accessed for a long time.

  • options

    • filename absolute file name

    • hash is the multihash of the file

await files.pin({hash : 'QmAs...'})

files.unpin(options)

Unpins the pinned file in MoiBit , so that garbage Collector got the access to collect the file which was not accessed for a long time.

  • options

    • filename absolute file name

    • hash is the multihash of the file

await files.unpin({filename : 'parent1/folder2/file3.txt'});

files.filedetail(path)

Returns complete detail about the file

await files.filedetail('parent1/folder2/file3.txt');

files.storageDetails(unit)

Returns all the storage details of the particular account (you did init with) in specific Unit.

  • unit is a short hand notation of storage unit. It can be B , KB , MB , GB , TB (case insensitive)
await files.storageDetails('mb');

Maintainers

  1. Vuppala Sai Prashanth
  2. Arunprakash

Review and code standards

  1. Ganesh Prasad Kumble

Support

If you need more clarifications, feel free to join our Telegram or Slack community channels. You can also write us an email at hello@moibit.io

License

GNU General Public License v3.0