]> git.r.bdr.sh - rbdr/mobius/commitdiff
Fix io.Reader implementation for FileNameWithInfo
authorJeff Halter <redacted>
Mon, 17 Jun 2024 18:40:34 +0000 (11:40 -0700)
committerJeff Halter <redacted>
Mon, 17 Jun 2024 18:40:34 +0000 (11:40 -0700)
hotline/file_name_with_info.go

index 4d59dd038bd8aef6e0aa8d274809d57dc45fcf3d..3324a6252e837be1b2619bfe24c3c036efd36462 100644 (file)
@@ -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) {