ipfs

package
v0.0.0-...-5bfea90 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2025 License: Apache-2.0, MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotDir = fmt.Errorf("not a directory")

Functions

func ExtractCarFile

func ExtractCarFile(carfilePath string, outputDir string) (extractedFiles int, err error)

ExtractCarFile extracts files from a Car (Content Addressable References) file. It reads the Car file at the specified path, extracts the files rooted at the provided CIDs, and saves them to the specified output directory.

The function returns the total number of extracted files and an error if any. If no files are extracted, it returns an error indicating so.

Parameters:

  • carfilePath: The path to the Car file to be extracted.
  • outputDir: The directory where the extracted files will be saved.

Returns:

  • extractedFiles: The total number of extracted files.
  • err: An error if any occurred during the extraction process.

func GetDATAFromIPFSCID

func GetDATAFromIPFSCID(ipfsC *IPFSClient, cid string) (D [][]byte, err error)

GetDATAFromIPFSCID retrieves the data from an IPFS CID, extracts the WASM files, and returns them as byte slices.

Parameters:

  • ipfsC: An instance of the IPFSClient struct, which provides methods for interacting with the IPFS network.
  • cid: The CID (Content Identifier) of the data to be retrieved from the IPFS network.

Returns:

  • D: A slice of byte slices, each representing the content of a WASM file extracted from the CID.
  • err: An error, if any, encountered during the retrieval or extraction process.

Note: This function assumes that the CID contains WASM files and that the extracted files are stored in a temporary directory.

Types

type IPFSClient

type IPFSClient struct {

	// LassieClientURL is the URL of the Lassie client
	LassieClientURL string
	// contains filtered or unexported fields
}

IPFSClient represents an IPFS client with its scheme, host, port and LassieClientURL details

func NewIPFSClient

func NewIPFSClient(scheme string, host string, port int) *IPFSClient

NewIPFSClient creates a new instance of IPFSClient with the provided scheme, host, and port. It also sets the LassieClientURL based on the provided scheme, host, and port.

func (*IPFSClient) GetDataFromCID

func (ipfsC *IPFSClient) GetDataFromCID(cid string) (data []byte, err error)

GetDataFromCID retrieves the data associated with the given CID from the IPFS node.

The function constructs an HTTP GET request to the LassieClientURL of the IPFSClient with the provided CID appended. It then sends the request and reads the response body into a byte slice.

Parameters:

  • cid (string) - The content identifier (CID) of the data to retrieve.

Returns:

  • data ([]byte) - The retrieved data from the IPFS node.
  • err (error) - An error if any occurs while constructing the request or reading the response.

func (*IPFSClient) GetURLFromCID

func (ipfsC *IPFSClient) GetURLFromCID(cid string) (cidUrl string, err error)

GetURLFromCID returns the URL of the given CID on the IPFS node.

The function constructs the URL by appending the provided CID to the LassieClientURL of the IPFSClient.

Parameters:

  • cid (string) - The content identifier (CID) of the data to retrieve.

Returns:

  • cidUrl (string) - The constructed URL of the given CID.
  • err (error) - An error if any occurs while constructing the URL.

Jump to

Keyboard shortcuts

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