9 type FileHeader struct {
10 Size [2]byte // Total size of FileHeader payload
11 Type [2]byte // 0 for file, 1 for dir
12 FilePath []byte // encoded file path
14 readOffset int // Internal offset to track read progress
17 func NewFileHeader(fileName string, isDir bool) FileHeader {
19 Type: [2]byte{0x00, 0x00},
20 FilePath: EncodeFilePath(fileName),
23 fh.Type = [2]byte{0x00, 0x01}
26 encodedPathLen := uint16(len(fh.FilePath) + len(fh.Type))
27 binary.BigEndian.PutUint16(fh.Size[:], encodedPathLen)
32 func (fh *FileHeader) Read(p []byte) (int, error) {
39 if fh.readOffset >= len(buf) {
40 return 0, io.EOF // All bytes have been read
43 n := copy(p, buf[fh.readOffset:])