feat: Add interchangeable write buffers based on io.File and filebuffer.Buffer

This commit is contained in:
Felix Pojtinger
2021-12-24 16:55:14 +01:00
parent 35ebd268a2
commit c8ff51d2c4
9 changed files with 159 additions and 69 deletions
+17 -5
View File
@@ -21,6 +21,17 @@ var (
ErrIsDirectory = errors.New("is a directory")
)
type WriteCache interface {
io.Closer
io.Reader
io.Seeker
io.Writer
Truncate(size int64) error
Size() (int64, error)
Sync() error
}
type File struct {
afero.File
@@ -33,7 +44,7 @@ type File struct {
link string
compressionLevel string
getFileBuffer func() (afero.File, func() error, error)
getFileBuffer func() (WriteCache, func() error, error)
name string
info os.FileInfo
@@ -44,7 +55,8 @@ type File struct {
readOpWriter io.WriteCloser
// TODO: Find a non-in-memory method to do this
writeBuf afero.File
writeBuf WriteCache
asdf afero.File
cleanWriteBuf func() error
onHeader func(hdr *models.Header)
@@ -60,7 +72,7 @@ func NewFile(
link string,
compressionLevel string,
getFileBuffer func() (afero.File, func() error, error),
getFileBuffer func() (WriteCache, func() error, error),
name string,
info os.FileInfo,
@@ -154,14 +166,14 @@ func (f *File) syncWithoutLocking() error {
}
done = true
stat, err := f.writeBuf.Stat()
size, err := f.writeBuf.Size()
if err != nil {
return config.FileConfig{}, err
}
f.info = &FileInfo{
name: f.info.Name(),
size: stat.Size(),
size: size,
mode: f.info.Mode(),
modTime: f.info.ModTime(),
isDir: f.info.IsDir(),
+2 -2
View File
@@ -31,7 +31,7 @@ type FileSystem struct {
metadata config.MetadataConfig
compressionLevel string
getFileBuffer func() (afero.File, func() error, error)
getFileBuffer func() (WriteCache, func() error, error)
onHeader func(hdr *models.Header)
}
@@ -43,7 +43,7 @@ func NewFileSystem(
metadata config.MetadataConfig,
compressionLevel string,
getFileBuffer func() (afero.File, func() error, error),
getFileBuffer func() (WriteCache, func() error, error),
onHeader func(hdr *models.Header),
) afero.Fs {