aboutsummaryrefslogtreecommitdiff
path: root/hotline
diff options
context:
space:
mode:
authorJeff Halter <868228+jhalter@users.noreply.github.com>2024-06-17 11:40:34 -0700
committerJeff Halter <868228+jhalter@users.noreply.github.com>2024-06-17 11:40:34 -0700
commit1a37f0144d0fd777771c6d870e3c3298947e2712 (patch)
tree8023ef6b560605ad95ec977b55aa63f93613fea4 /hotline
parent48ecb30da4babac9955891063f658207a31480ba (diff)
Fix io.Reader implementation for FileNameWithInfo
Diffstat (limited to 'hotline')
-rw-r--r--hotline/file_name_with_info.go33
1 files changed, 21 insertions, 12 deletions
diff --git a/hotline/file_name_with_info.go b/hotline/file_name_with_info.go
index 4d59dd0..3324a62 100644
--- a/hotline/file_name_with_info.go
+++ b/hotline/file_name_with_info.go
@@ -10,6 +10,8 @@ import (
type FileNameWithInfo struct {
fileNameWithInfoHeader
Name []byte // File Name
+
+ readOffset int // Internal offset to track read progress
}
// fileNameWithInfoHeader contains the fixed length fields of FileNameWithInfo
@@ -27,18 +29,25 @@ func (f *fileNameWithInfoHeader) nameLen() int {
}
// Read implements io.Reader for FileNameWithInfo
-func (f *FileNameWithInfo) Read(b []byte) (int, error) {
- return copy(b,
- slices.Concat(
- f.Type[:],
- f.Creator[:],
- f.FileSize[:],
- f.RSVD[:],
- f.NameScript[:],
- f.NameSize[:],
- f.Name,
- ),
- ), io.EOF
+func (f *FileNameWithInfo) Read(p []byte) (int, error) {
+ buf := slices.Concat(
+ f.Type[:],
+ f.Creator[:],
+ f.FileSize[:],
+ f.RSVD[:],
+ f.NameScript[:],
+ f.NameSize[:],
+ f.Name,
+ )
+
+ if f.readOffset >= len(buf) {
+ return 0, io.EOF // All bytes have been read
+ }
+
+ n := copy(p, buf[f.readOffset:])
+ f.readOffset += n
+
+ return n, nil
}
func (f *FileNameWithInfo) Write(p []byte) (int, error) {