ipfsmgr

package module
v0.9.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 13, 2022 License: MIT Imports: 21 Imported by: 0

README

IPFS Manager

Abstract

This is a golang module to manager IPFS file and directory.

It's a part of IPFS grant service for enterprice.

The main functions of the library is:

  • Add files and directories to IPFS
  • Get files and directories from IPFS

This module tested on Ubuntu Linux 2020

If you have any problem please contact the author.

Env

Getting started

get ipfsmgr mod

go get -u github.com/filecoincrypto/ipfsmgr

then import the mod as normal.

import (
  m "github.com/filecoincrypto/ipfsmgr"
)

Build from source

First you must add golang and ipfs CLI.

git clone https://github.com/filecoincrypto/ipfsmgr.git

go clean --modcache

go mod tidy

go build -mod=mod

go install

Install ipfs on Linux

wget https://dist.ipfs.io/go-ipfs/v0.13.1/go-ipfs_v0.13.1_linux-amd64.tar.gz --no-check-certificate
tar -xvzf go-ipfs_v0.13.1_linux-amd64.tar.gz

> x go-ipfs/install.sh
> x go-ipfs/ipfs

cd go-ipfs
sudo bash install.sh

> Moved ./ipfs to /usr/local/bin
ipfs --version

> ipfs version 0.13.1

Running a test

To run the test, just do:

> go test

Trouble shooting

  • missing go.sum entry for module providing package ...
    run go build -mod=mod will generate go.sum

  • panic: failed to spawn ephemeral node: no IPFS repo found in /home/zhh/.ipfs.
    please install go-ipfs and run: 'ipfs init'.

  • failed to spawn ephemeral node: failed to init ephemeral node: unknown datastore type: flatfs
    run ipfs init first

  • failed to spawn ephemeral node: no version file found, please run 0-to-1 migration tool.
    See https://github.com/ipfs/fs-repo-migrations/blob/master/run.md
    Sorry for the inconvenience. In the future, these will run automatically.
    not init repo directory correctly. run ipfs init first.

  • failed to sufficiently increase receive buffer size
    run sudo sysctl -w net.core.rmem_max=2500000, This command would increase the maximum receive buffer size to roughly 2.5 MB

Reference

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IIpfsMgr

type IIpfsMgr interface {
	// AddIpfsFile upload local file to IPFS
	AddIpfsFile(inputPathFile string) (cidFile icorepath.Path, err error)
	// AddIpfsDir upload local directory to IPFS
	AddIpfsDir(inputPath string) (cidPath icorepath.Path, err error)
	// GetIpfsFile download IPFS cid file to outputPathFile
	GetIpfsFile(cidPath string, outputPathFile string) (err error)
	// GetIpfsDir download IPFS cid path to outputPath
	GetIpfsDir(cidPath string, outputPath string) (err error)
}

type IIpfsMgr is an interface of type IpfsMgr

type IpfsMgr

type IpfsMgr struct {
	// contains filtered or unexported fields
}

type IpfsMgr, create repo, collect to peers, add and get ipfs files.

func NewIpfsMgr

func NewIpfsMgr(repoPath string) *IpfsMgr

NewIpfsMgr new instance of IpfsMgr repoPath could be empty, default is ~/.ipfs

func (*IpfsMgr) AddIpfsDir

func (mgr *IpfsMgr) AddIpfsDir(inputPath string) (cidPath icorepath.Path, err error)

AddIpfsDir add local directory to IPFS

func (*IpfsMgr) AddIpfsFile

func (mgr *IpfsMgr) AddIpfsFile(inputPathFile string) (cidFile icorepath.Path, err error)

AddIpfsFile add local file to IPFS

func (*IpfsMgr) ConnectToPeers

func (mgr *IpfsMgr) ConnectToPeers(peers []string) error

ConnectToPeers connect peers, there are default bootstrap peers. param peers could be nil or empty, or you can add your own peers.

func (*IpfsMgr) CreateNode

func (mgr *IpfsMgr) CreateNode(repoPath string) (api icore.CoreAPI, err error)

CreateNode Creates an IPFS node and returns its coreAPI param repoPath could be empty and set to default ~/.ipfs MUST use `ipfs init` to init ~/.ipfs as a repo

func (*IpfsMgr) CreateRepo

func (mgr *IpfsMgr) CreateRepo(repoPath string) error

CreateRepo create and config a repo

func (*IpfsMgr) GetIpfsDir

func (mgr *IpfsMgr) GetIpfsDir(cidPath string, outputPath string) (err error)

GetIpfsDir from cidPath string

func (*IpfsMgr) GetIpfsDirFromCid

func (mgr *IpfsMgr) GetIpfsDirFromCid(cidDirectory icorepath.Path, outputPath string) (err error)

GetIpfsDirFromCid from cidDirectory from github.com/ipfs/interface-go-ipfs-core/path.Path

func (*IpfsMgr) GetIpfsFile

func (mgr *IpfsMgr) GetIpfsFile(cidPath string, outputPathFile string) (err error)

GetIpfsFile from cidPath string.

func (*IpfsMgr) GetIpfsFileFromCid

func (mgr *IpfsMgr) GetIpfsFileFromCid(cidFile icorepath.Path, outputPathFile string) (err error)

GetIpfsFile from cidFile from github.com/ipfs/interface-go-ipfs-core/path.Path

func (*IpfsMgr) GetLocalFile

func (mgr *IpfsMgr) GetLocalFile(path string) (files.File, error)

GetLocalFile read local file content ipfs File include Node interface and io.Reader io.Seeker

func (*IpfsMgr) GetLocalNode

func (mgr *IpfsMgr) GetLocalNode(path string) (files.Node, error)

GetLocalNode get local file node ipfs Node is a common interface for files, directories and other special files

func (*IpfsMgr) GetRepoPath added in v0.9.1

func (mgr *IpfsMgr) GetRepoPath() (string, error)

func (*IpfsMgr) SetupPlugins

func (mgr *IpfsMgr) SetupPlugins(pluginsPath string) (*loader.PluginLoader, error)

SetupPlugins setup repo external plugins directors and load the plugins

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL