github.com/koko1123/flow-go-1@v0.29.6/engine/execution/ingestion/uploader/file_uploader.go (about)

     1  package uploader
     2  
     3  import (
     4  	"bufio"
     5  	"fmt"
     6  	"os"
     7  	"path"
     8  
     9  	"github.com/koko1123/flow-go-1/engine/execution"
    10  )
    11  
    12  func NewFileUploader(dir string) *FileUploader {
    13  	return &FileUploader{
    14  		dir: dir,
    15  	}
    16  }
    17  
    18  type FileUploader struct {
    19  	dir string
    20  }
    21  
    22  func (f *FileUploader) Upload(computationResult *execution.ComputationResult) error {
    23  	file, err := os.Create(path.Join(f.dir, fmt.Sprintf("%s.cbor", computationResult.ExecutableBlock.ID())))
    24  	if err != nil {
    25  		return fmt.Errorf("cannot create file for writing block data: %w", err)
    26  	}
    27  	defer file.Close()
    28  
    29  	writer := bufio.NewWriter(file)
    30  	defer writer.Flush()
    31  
    32  	return WriteComputationResultsTo(computationResult, writer)
    33  }