aboutsummaryrefslogtreecommitdiff
path: root/hotline/file_transfer.go
diff options
context:
space:
mode:
authorJeff Halter <868228+jhalter@users.noreply.github.com>2026-03-15 20:48:45 -0700
committerJeff Halter <868228+jhalter@users.noreply.github.com>2026-03-15 20:48:45 -0700
commit92f4b7af1073b6cdd0786ce2090d6e446e0903ad (patch)
tree4cfb332a36aa093d6bb4238967f1b0728fbb498f /hotline/file_transfer.go
parentf78ab940a8c09702be3e0ba310ac56e02fa76701 (diff)
Extract shared readFrom helper to deduplicate io.Reader boilerplate
13 types implemented identical offset-based io.Reader patterns with 5-7 lines of copy-and-offset-tracking code each. Extract a shared readFrom(p, offset, data) helper and reduce each Read() method to a one-liner delegating to it.
Diffstat (limited to 'hotline/file_transfer.go')
-rw-r--r--hotline/file_transfer.go9
1 files changed, 1 insertions, 8 deletions
diff --git a/hotline/file_transfer.go b/hotline/file_transfer.go
index e8acbb3..e5898db 100644
--- a/hotline/file_transfer.go
+++ b/hotline/file_transfer.go
@@ -241,14 +241,7 @@ func (fh *FileHeader) Read(p []byte) (int, error) {
fh.FilePath,
)
- if fh.readOffset >= len(buf) {
- return 0, io.EOF // All bytes have been read
- }
-
- n := copy(p, buf[fh.readOffset:])
- fh.readOffset += n
-
- return n, nil
+ return readFrom(p, &fh.readOffset, buf)
}
func DownloadHandler(w io.Writer, fullPath string, fileTransfer *FileTransfer, fs FileStore, rLogger *slog.Logger, preserveForks bool) error {