]> git.r.bdr.sh - rbdr/mobius/blobdiff - hotline/file_header.go
Refactoring, cleanup, test backfilling
[rbdr/mobius] / hotline / file_header.go
index 71a1c003044199913a553d14f6d41f50429a3521..b18229a666a5d66ead8435fa73eb60d8e6e0a064 100644 (file)
@@ -10,11 +10,12 @@ 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 {
        fh := FileHeader{
-               Type:     [2]byte{0x00, 0x00},
                FilePath: EncodeFilePath(fileName),
        }
        if isDir {
@@ -28,10 +29,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
 }