-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1 parent
7e571a2
commit fd80abb
Showing
2 changed files
with
51 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package persistent | ||
|
||
import ( | ||
"io" | ||
"os" | ||
|
||
"github.com/pkg/errors" | ||
|
||
"github.com/outofforest/quantum/types" | ||
) | ||
|
||
// NewFileStore creates new file-based store. | ||
func NewFileStore(file *os.File) *FileStore { | ||
return &FileStore{ | ||
file: file, | ||
} | ||
} | ||
|
||
// FileStore defines persistent file-based store. | ||
type FileStore struct { | ||
file *os.File | ||
} | ||
|
||
// Write writes data to the store. | ||
func (s *FileStore) Write(address types.PhysicalAddress, data []byte) error { | ||
if _, err := s.file.Seek(int64(address), io.SeekStart); err != nil { | ||
return errors.WithStack(err) | ||
} | ||
_, err := s.file.Write(data) | ||
return errors.WithStack(err) | ||
} |