Esempio n. 1
0
func pinFiles(csvfile string) (string, error) {
	var err error

	csvFile, err := os.Open(csvfile)
	if err != nil {
		return "", fmt.Errorf("error opening csv file: %v\n", err)
	}
	defer csvFile.Close()

	reader := csv.NewReader(csvFile)
	rawCSVdata, err := reader.ReadAll()
	if err != nil {
		return "", fmt.Errorf("error reading csv file: %v\n", err)
	}

	hashArray := make([]string, len(rawCSVdata))
	for i, each := range rawCSVdata {
		if logger.Level > 0 {
			hashArray[i], err = ipfs.PinToIPFS(each[0], logger.Writer)
		} else {
			hashArray[i], err = ipfs.PinToIPFS(each[0], bytes.NewBuffer([]byte{}))
		}
		if err != nil {
			return "", err
		}
	}
	hashes := strings.Join(hashArray, "\n")
	return hashes, nil
}
Esempio n. 2
0
func pinFile(fileHash string) (string, error) {
	var hash string
	var err error

	if logger.Level > 0 {
		hash, err = ipfs.PinToIPFS(fileHash, logger.Writer)
	} else {
		hash, err = ipfs.PinToIPFS(fileHash, bytes.NewBuffer([]byte{}))
	}
	if err != nil {
		return "", err
	}
	return hash, nil
}
Esempio n. 3
0
func pinFile(fileHash string) (string, error) {
	var hash string
	var err error

	if log.GetLevel() > 0 {
		hash, err = ipfs.PinToIPFS(fileHash, os.Stdout)
	} else {
		hash, err = ipfs.PinToIPFS(fileHash, bytes.NewBuffer([]byte{}))
	}
	if err != nil {
		return "", err
	}
	return hash, nil
}