aboutsummaryrefslogtreecommitdiff
path: root/hotline/file_header.go
diff options
context:
space:
mode:
authorJeff Halter <868228+jhalter@users.noreply.github.com>2024-06-17 13:50:28 -0700
committerJeff Halter <868228+jhalter@users.noreply.github.com>2024-06-17 13:50:28 -0700
commit45ca5d60383cbe270624c713b916da29af7ba88f (patch)
treea6f8b9ecf24837e8588390ae5bdf5fdef711fed9 /hotline/file_header.go
parent5954ccad9c87063231f3a8bb3e5d01675a9865ca (diff)
Fix io.Reader implementations and wrap more errors
Diffstat (limited to 'hotline/file_header.go')
-rw-r--r--hotline/file_header.go16
1 files changed, 13 insertions, 3 deletions
diff --git a/hotline/file_header.go b/hotline/file_header.go
index 71a1c00..469f321 100644
--- a/hotline/file_header.go
+++ b/hotline/file_header.go
@@ -10,6 +10,8 @@ type FileHeader struct {
Size [2]byte // Total size of FileHeader payload
Type [2]byte // 0 for file, 1 for dir
FilePath []byte // encoded file path
+
+ readOffset int // Internal offset to track read progress
}
func NewFileHeader(fileName string, isDir bool) FileHeader {
@@ -28,10 +30,18 @@ func NewFileHeader(fileName string, isDir bool) FileHeader {
}
func (fh *FileHeader) Read(p []byte) (int, error) {
- return copy(p, slices.Concat(
+ buf := slices.Concat(
fh.Size[:],
fh.Type[:],
fh.FilePath,
- ),
- ), io.EOF
+ )
+
+ 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
}