aboutsummaryrefslogtreecommitdiff
path: root/hotline/file_header.go
diff options
context:
space:
mode:
authorJeff Halter <868228+jhalter@users.noreply.github.com>2024-06-09 13:56:29 -0700
committerJeff Halter <868228+jhalter@users.noreply.github.com>2024-06-09 14:05:15 -0700
commit9cf66aeafbcbb9237fedc2efc97cc2856eb60f7f (patch)
treec3139d8af2bd6ae106a1f619cad7d64f2ddea6db /hotline/file_header.go
parentb129b7cbc9fd9a9c11a77e5922861ef08893efa1 (diff)
Convert more bespoke methods to io.Reader/io.Writer interfaces
Diffstat (limited to 'hotline/file_header.go')
-rw-r--r--hotline/file_header.go25
1 files changed, 13 insertions, 12 deletions
diff --git a/hotline/file_header.go b/hotline/file_header.go
index 61b8e28..71a1c00 100644
--- a/hotline/file_header.go
+++ b/hotline/file_header.go
@@ -2,35 +2,36 @@ package hotline
import (
"encoding/binary"
+ "io"
"slices"
)
type FileHeader struct {
- Size []byte // Total size of FileHeader payload
- Type []byte // 0 for file, 1 for dir
- FilePath []byte // encoded file path
+ Size [2]byte // Total size of FileHeader payload
+ Type [2]byte // 0 for file, 1 for dir
+ FilePath []byte // encoded file path
}
func NewFileHeader(fileName string, isDir bool) FileHeader {
fh := FileHeader{
- Size: make([]byte, 2),
- Type: []byte{0x00, 0x00},
+ Type: [2]byte{0x00, 0x00},
FilePath: EncodeFilePath(fileName),
}
if isDir {
- fh.Type = []byte{0x00, 0x01}
+ fh.Type = [2]byte{0x00, 0x01}
}
encodedPathLen := uint16(len(fh.FilePath) + len(fh.Type))
- binary.BigEndian.PutUint16(fh.Size, encodedPathLen)
+ binary.BigEndian.PutUint16(fh.Size[:], encodedPathLen)
return fh
}
-func (fh *FileHeader) Payload() []byte {
- return slices.Concat(
- fh.Size,
- fh.Type,
+func (fh *FileHeader) Read(p []byte) (int, error) {
+ return copy(p, slices.Concat(
+ fh.Size[:],
+ fh.Type[:],
fh.FilePath,
- )
+ ),
+ ), io.EOF
}