File specification processing

When serving as a storage service, file specification processing is the first step in file storage.

File specification processing will cut the file into pieces according to the size of 64M, and fill the insufficient parts with zero. The cut file will soon become a segment. Then each segment will be redundantly processed to obtain 6 file fragments with a size of 16M, which is called For fragments, arrange all fragments in segment order called a tree structure, calculate the hash-256 values of all fragments, and the final calculated root hash of the tree is the root hash of the file, also called fid, which is used to uniquely identify the file. document.

Refer to the following code:

package main

import (
	"context"
	"fmt"

	cess "github.com/CESSProject/cess-go-sdk"
)

// Substrate well-known mnemonic:
//
//	https://github.com/substrate-developer-hub/substrate-developer-hub.github.io/issues/613
var MY_MNEMONIC = "bottom drive obey lake curtain smoke basket hold race lonely fit walk"

var RPC_ADDRS = []string{
	"wss://testnet-rpc0.cess.cloud/ws/",
	"wss://testnet-rpc1.cess.cloud/ws/",
	"wss://testnet-rpc2.cess.cloud/ws/",
}

func main() {
	sdk, err := cess.New(
		context.Background(),
		cess.ConnectRpcAddrs(RPC_ADDRS),
		cess.Mnemonic(MY_MNEMONIC),
	)
	if err != nil {
		panic(err)
	}
	// Processing file
	segmentDataInfo, fid, err := sdk.ShardedEncryptionProcessing("test_file", "")
	if err != nil {
		panic(err)
	}
	// Print segment data and fid
	fmt.Println(segmentDataInfo, fid)
}

Last updated