core

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2024 License: MIT Imports: 14 Imported by: 6

Documentation

Overview

Package core defines structure to hold data and relative functions.

Index

Constants

View Source
const (
	// DefaultChunkSize represents the default chunk size in bytes.
	DefaultChunkSize = 256

	// DefaultSegmentMaxChunks represents the default maximum number of chunks within a segment.
	DefaultSegmentMaxChunks = 1024

	// DefaultSegmentSize represents the default segment size in bytes.
	DefaultSegmentSize = DefaultChunkSize * DefaultSegmentMaxChunks
)

Variables

View Source
var (
	EmptyChunk     = make([]byte, DefaultChunkSize)
	EmptyChunkHash = crypto.Keccak256Hash(EmptyChunk)
)
View Source
var (
	// ErrFileRequired is returned when manipulate on a folder.
	ErrFileRequired = errors.New("file required")

	// ErrFileEmpty is returned when empty file opened.
	ErrFileEmpty = errors.New("file is empty")
)

Functions

func ComputePaddedSize

func ComputePaddedSize(chunks uint64) (uint64, uint64)

func Exists

func Exists(name string) (bool, error)

func IteratorPaddedSize

func IteratorPaddedSize(dataSize int64, flowPadding bool) uint64

func MerkleTree

func MerkleTree(data IterableData) (*merkle.Tree, error)

MerkleTree create merkle tree of the data.

func NumSegmentsPadded

func NumSegmentsPadded(data IterableData) int

NumSegmentsPadded return the number of segments of padded data

func NumSplits

func NumSplits(total int64, unit int) uint64

func ReadAt

func ReadAt(data IterableData, readSize int, offset int64, paddedSize uint64) ([]byte, error)

ReadAt read data at specified offset, paddedSize is the size of data after padding.

func SegmentRoot

func SegmentRoot(chunks []byte, emptyChunksPadded ...uint64) common.Hash

SegmentRoot return the merkle root of given chunks

Types

type DataInMemory

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

DataInMemory implement of IterableData, the underlying is memory data

func NewDataInMemory

func NewDataInMemory(data []byte) (*DataInMemory, error)

NewDataInMemory creates DataInMemory from given data

func (*DataInMemory) Iterate

func (data *DataInMemory) Iterate(offset int64, batch int64, flowPadding bool) Iterator

func (*DataInMemory) NumChunks

func (data *DataInMemory) NumChunks() uint64

func (*DataInMemory) NumSegments

func (data *DataInMemory) NumSegments() uint64

func (*DataInMemory) PaddedSize

func (data *DataInMemory) PaddedSize() uint64

func (*DataInMemory) Read

func (data *DataInMemory) Read(buf []byte, offset int64) (int, error)

func (*DataInMemory) Size

func (data *DataInMemory) Size() int64

type File

type File struct {
	os.FileInfo
	// contains filtered or unexported fields
}

File implement of IterableData, the underlying is a file on disk

func Open

func Open(name string) (*File, error)

Open create a File from a file on disk

func (*File) Close

func (file *File) Close() error

func (*File) Iterate

func (file *File) Iterate(offset int64, batch int64, flowPadding bool) Iterator

func (*File) NumChunks

func (file *File) NumChunks() uint64

func (*File) NumSegments

func (file *File) NumSegments() uint64

func (*File) PaddedSize

func (file *File) PaddedSize() uint64

func (*File) Read

func (file *File) Read(buf []byte, offset int64) (int, error)

type FileIterator

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

func (*FileIterator) Current

func (it *FileIterator) Current() []byte

func (*FileIterator) Next

func (it *FileIterator) Next() (bool, error)

type Flow

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

func NewFlow

func NewFlow(data IterableData, tags []byte, opts ...common.LogOption) *Flow

func (*Flow) CreateSubmission

func (flow *Flow) CreateSubmission() (*contract.Submission, error)

type IterableData

type IterableData interface {
	NumChunks() uint64
	NumSegments() uint64
	Size() int64
	PaddedSize() uint64
	Iterate(offset int64, batch int64, flowPadding bool) Iterator
	Read(buf []byte, offset int64) (int, error)
}

IterableData defines the data interface to upload to 0g storage network.

type Iterator

type Iterator interface {
	Next() (bool, error)
	Current() []byte
}

type MemoryDataIterator

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

func (*MemoryDataIterator) Current

func (it *MemoryDataIterator) Current() []byte

func (*MemoryDataIterator) Next

func (it *MemoryDataIterator) Next() (bool, error)

type TreeBuilderInitializer

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

func (*TreeBuilderInitializer) ParallelCollect

func (t *TreeBuilderInitializer) ParallelCollect(result *parallel.Result) error

ParallelCollect implements parallel.Interface.

func (*TreeBuilderInitializer) ParallelDo

func (t *TreeBuilderInitializer) ParallelDo(ctx context.Context, routine int, task int) (interface{}, error)

ParallelDo implements parallel.Interface.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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