70 lines
1.2 KiB
Go

package ocean
// import (
// "bufio"
// "encoding/json"
// "io"
// "os"
// "path/filepath"
// )
//
// type FileStorage[T any] struct {
// collection *collection[T]
// dirty chan struct{}
// }
//
// func (fs *FileStorage[T]) Init(c *collection[T]) error {
// fs.collection = c
// fileName := filepath.Join(c.root, c.name+".dat")
// stream, err := os.OpenFile(fileName, os.O_RDONLY, 0600)
//
// if os.IsNotExist(err) {
// return nil
// }
//
// if err != nil {
// return err
// }
//
// defer stream.Close()
// return fs.readRecords(stream)
// }
//
// func (fs *FileStorage[T]) Set(key string, value *T) error {
// return nil
// }
//
// func (fs *FileStorage[T]) Delete(key string) error {
// return nil
// }
//
// // readRecords reads the entire collection.
// func (fs *FileStorage[T]) readRecords(stream io.Reader) error {
// var (
// key string
// value []byte
// )
//
// scanner := bufio.NewScanner(stream)
//
// for scanner.Scan() {
// if key == "" {
// key = scanner.Text()
// continue
// }
//
// value = scanner.Bytes()
// object := new(T)
// err := json.Unmarshal(value, object)
//
// if err != nil {
// return err
// }
//
// fs.collection.data.Store(key, object)
// key = ""
// }
//
// return nil
// }