X-Git-Url: https://git.r.bdr.sh/rbdr/mobius/blobdiff_plain/72dd37f1abb2b550aaaac48eac677403d5664797..e995052ef530b1eae2d0476ff519f7225bbb481d:/hotline/file_header.go?ds=sidebyside diff --git a/hotline/file_header.go b/hotline/file_header.go index 7e0df16..71a1c00 100644 --- a/hotline/file_header.go +++ b/hotline/file_header.go @@ -2,44 +2,36 @@ package hotline import ( "encoding/binary" - "github.com/jhalter/mobius/concat" + "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) Read(p []byte) (n int, err error) { - p = concat.Slices( - fh.Size, - fh.Type, +func (fh *FileHeader) Read(p []byte) (int, error) { + return copy(p, slices.Concat( + fh.Size[:], + fh.Type[:], fh.FilePath, - ) - return len(p), nil -} - -func (fh *FileHeader) Payload() []byte { - return concat.Slices( - fh.Size, - fh.Type, - fh.FilePath, - ) + ), + ), io.EOF }