util

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2024 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalculateFileCid

func CalculateFileCid(fileReader io.Reader) (string, error)

CalculateFileCid gets the CIDv1 for the given data, the same as IPFS kubo would. It does not load the whole file into memory.

func Fatal

func Fatal(err error)

fatal kills the program if the provided err is not nil, logging it as well.

func GenerateEncKey

func GenerateEncKey(cid, attr string) (encKeyPath string, encKeyBytes []byte, isNew bool, err error)

GenerateEncKey generates a new encryption key for the given CID and attribute and stores it in a file. If the key already exists, it is read from the file.

func GetCAR

func GetCAR(r io.Reader, useDisk bool) (*car.CarV1, error)

GetCAR returns a CARv1 file created from the provided reader. Currently this uses the default IPFS kubo settings under the hood, and so the CIDv1 represented by the CAR file should exactly match the CIDv1 from CalculateFileCid or IPFS kubo every time.

Set useDisk to control whether this function holds the read bytes all in memory or stores them on the disk temporarily.

If useDisk is true, the caller should call RemoveCarTmpDatastore once they are done with the returned *car.CarV1 struct. This will clear the datastore from the disk.

func GuessMediaType

func GuessMediaType(path string) (string, error)

GuessMediaType guesses the media type of a file based on its contents. The 'media_type' attribute should be preferred over this method.

func MoveFile

func MoveFile(sourcePath, destPath string) error

MoveFile moves the provided file, even if source and dest are part of different file systems.

It is not atomic. os.Rename should be used in favour of this function if it can be guaranteed that source and dest are on the same filesystem, or atomicity is required.

func RemoveCarTmpDatastore

func RemoveCarTmpDatastore() error

func Runner

func Runner(args []string, run RunFunc)

Runner runs your command and does pre/post processing. args should not contain the name of the command/binary.

func TempDir

func TempDir() string

func Version

func Version() string

Types

type RunFunc

type RunFunc func([]string) error

Jump to

Keyboard shortcuts

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