fix: add a read state so we can noop a seek when we have not done anything yet

This commit is contained in:
Derrick Hammer 2024-01-24 19:47:25 -05:00
parent 14d8760c1f
commit 84bb08144b
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 7 additions and 1 deletions

View File

@ -21,10 +21,11 @@ type File struct {
storage interfaces.StorageService
record *models.Upload
cid *encoding.CID
read bool
}
func NewFile(hash []byte, storage interfaces.StorageService) *File {
return &File{hash: hash, storage: storage}
return &File{hash: hash, storage: storage, read: false}
}
func (f *File) Exists() bool {
@ -38,6 +39,7 @@ func (f *File) Read(p []byte) (n int, err error) {
if err != nil {
return 0, err
}
f.read = true
return f.reader.Read(p)
}
@ -45,6 +47,10 @@ func (f *File) Read(p []byte) (n int, err error) {
func (f *File) Seek(offset int64, whence int) (int64, error) {
switch whence {
case io.SeekStart:
if !f.read {
return 0, nil
}
if f.reader != nil {
err := f.reader.Close()
if err != nil {