github.com/unicornultrafoundation/go-u2u@v1.0.0-rc1.0.20240205080301-e74a83d3fadc/u2u/genesisstore/fileshash/reader_map.go (about)

     1  package fileshash
     2  
     3  import (
     4  	"io"
     5  
     6  	"github.com/unicornultrafoundation/go-helios/hash"
     7  )
     8  
     9  type Map struct {
    10  	backend func(string) (io.Reader, error)
    11  }
    12  
    13  func Wrap(backend func(string) (io.Reader, error), maxMemoryUsage uint64, roots map[string]hash.Hash) func(string) (io.Reader, error) {
    14  	return func(name string) (io.Reader, error) {
    15  		root, ok := roots[name]
    16  		if !ok {
    17  			return nil, ErrRootNotFound
    18  		}
    19  		f, err := backend(name)
    20  		if err != nil {
    21  			return nil, err
    22  		}
    23  		return WrapReader(f, maxMemoryUsage, root), nil
    24  	}
    25  }