-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add local file persister #1195
Add local file persister #1195
Conversation
3dc6b6f
to
b797637
Compare
This interface is what the local persister and remote persister will have to conform to. It will allow the browser module to easily abstract away the detail of where and how the file is being persisted.
The file persister will either be a local one or a remote one. The decision will be made when the moduleVU is created, and one will be initialised and set in the moduleVU instance.
b797637
to
a1811ba
Compare
f814d97
to
7a72b00
Compare
7a72b00
to
991e511
Compare
storage/file_persister.go
Outdated
func write(w io.Writer, r io.Reader) error { | ||
buf := make([]byte, 4096) | ||
for { | ||
n, err := r.Read(buf) | ||
if n > 0 { | ||
if _, writeErr := w.Write(buf[:n]); writeErr != nil { | ||
return fmt.Errorf("writing to the local writer: %w", writeErr) | ||
} | ||
} | ||
if err == io.EOF { | ||
break | ||
} | ||
if err != nil { | ||
return fmt.Errorf("reading from the reader: %w", err) | ||
} | ||
} | ||
|
||
return nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't we just use io.Copy
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no idea how i missed that 😆. Good suggestion, added to 7c39fb9
storage/file_persister.go
Outdated
} | ||
defer func() { | ||
if err := f.Close(); err != nil { | ||
logger.Errorf("LocalFilePersister:Persist", "closing the local file %q: %v", cp, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can handle this also from the call site if we return an error here. So we don't have to pass a logger here. The call site can log the error if it sees it's a file close error. WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that's a nice idea! Added it to 9476537
In which case the logger
can be removed and has been 🎉
cfa2726
to
80acf99
Compare
This is the file persister that will be used when testing locally. This will replace the current implementation that is in screenshotter.
80acf99
to
0c350c1
Compare
Return an error to the caller if the close errors, but only if there isn't an existing error. This helps removes the logger that is no longer needed.
b4b354e
to
9476537
Compare
de5f6be
to
f35a27a
Compare
Closing this and moving this to #1197 |
What?
This adds a local file persister which will save files to the local disk. It implements the interface defined in #1155.
Why?
So that we can replace how we're currently writing screenshots to disk. This will help hide the details of where and how the files are saved, allowing us to easily work with different file persisters.
Checklist
Related PR(s)/Issue(s)
Updates: #1156