fix: add a read state so we can noop a seek when we have not done anything yet
This commit is contained in:
parent
14d8760c1f
commit
84bb08144b
|
@ -21,10 +21,11 @@ type File struct {
|
||||||
storage interfaces.StorageService
|
storage interfaces.StorageService
|
||||||
record *models.Upload
|
record *models.Upload
|
||||||
cid *encoding.CID
|
cid *encoding.CID
|
||||||
|
read bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFile(hash []byte, storage interfaces.StorageService) *File {
|
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 {
|
func (f *File) Exists() bool {
|
||||||
|
@ -38,6 +39,7 @@ func (f *File) Read(p []byte) (n int, err error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
f.read = true
|
||||||
|
|
||||||
return f.reader.Read(p)
|
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) {
|
func (f *File) Seek(offset int64, whence int) (int64, error) {
|
||||||
switch whence {
|
switch whence {
|
||||||
case io.SeekStart:
|
case io.SeekStart:
|
||||||
|
if !f.read {
|
||||||
|
return 0, nil
|
||||||
|
}
|
||||||
|
|
||||||
if f.reader != nil {
|
if f.reader != nil {
|
||||||
err := f.reader.Close()
|
err := f.reader.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue