func (s *SimpleSplitterJob) writeToLevel(lvl int, data []byte) error {
	copy(s.buffer[s.cursors[lvl]:s.cursors[lvl]+len(data)], data)
	s.cursors[lvl] += len(data)
	if s.cursors[lvl]-s.cursors[lvl+1] == swarm.ChunkSize {
		ref, err := s.sumLevel(lvl)
		if err != nil {
			return err
		}
		err = s.writeToLevel(lvl+1, ref)
		if err != nil {
			return err
		}
		s.cursors[lvl] = s.cursors[lvl+1]
	}
	return nil
}
writeToLevel writes to the data buffer on the specified level.
It calls sum if chunk boundary is reached and recursively calls this function for
the next level with the acquired bmt hash

It adjusts the relevant levels' cursors accordingly.
package internal
import (
	"context"
	"encoding/binary"
	"errors"
	"fmt"
	"github.com/ethsana/sana/pkg/cac"
	"github.com/ethsana/sana/pkg/encryption"
	"github.com/ethsana/sana/pkg/file"
	"github.com/ethsana/sana/pkg/sctx"
	"github.com/ethsana/sana/pkg/swarm"
	"github.com/ethsana/sana/pkg/tags"
	"golang.org/x/crypto/sha3"
)
type Putter interface {
	Put(context.Context, swarm.Chunk) ([]bool, error)
}
const levelBufferLimit = 9
type SimpleSplitterJob struct {
	ctx        context.Context
	putter     Putter
	spanLength int64   
	length     int64   
	sumCounts  []int   
	cursors    []int   
	buffer     []byte  
	tag        *tags.Tag
	toEncrypt  bool  
	refSize    int64
}
func NewSimpleSplitterJob(ctx context.Context, putter Putter, spanLength int64, toEncrypt bool) *SimpleSplitterJob {
	hashSize := swarm.HashSize
	refSize := int64(hashSize)
	if toEncrypt {
		refSize += encryption.KeyLength
	}
	return &SimpleSplitterJob{
		ctx:        ctx,
		putter:     putter,
		spanLength: spanLength,
		sumCounts:  make([]int, levelBufferLimit),
		cursors:    make([]int, levelBufferLimit),
		buffer:     make([]byte, swarm.ChunkWithSpanSize*levelBufferLimit*2),  
		tag:        sctx.GetTag(ctx),
		toEncrypt:  toEncrypt,
		refSize:    refSize,
	}
}
func (j *SimpleSplitterJob) Write(b []byte) (int, error) {
	if len(b) > swarm.ChunkSize {
		return 0, fmt.Errorf("Write must be called with a maximum of %d bytes", swarm.ChunkSize)
	}
	j.length += int64(len(b))
	if j.length > j.spanLength {
		return 0, errors.New("write past span length")
	}
	err := j.writeToLevel(0, b)
	if err != nil {
		return 0, err
	}
	if j.length == j.spanLength {
		err := j.hashUnfinished()
		if err != nil {
			return 0, file.NewHashError(err)
		}
		err = j.moveDanglingChunk()
		if err != nil {
			return 0, file.NewHashError(err)
		}
	}
	return len(b), nil
}
func (j *SimpleSplitterJob) Sum(b []byte) []byte {
	return j.digest()
}