]> git.r.bdr.sh - rbdr/mobius/blob - hotline/file_name_with_info.go
First pass at file browsing
[rbdr/mobius] / hotline / file_name_with_info.go
1 package hotline
2
3 import (
4 "encoding/binary"
5 "github.com/jhalter/mobius/concat"
6 )
7
8 // FileNameWithInfo field content is presented in this structure:
9 // Type 4 Folder (‘fldr’) or other
10 // Creator 4
11 // File size 4
12 // 4 Reserved?
13 // Name script 2
14 // Name size 2
15 // Name data size
16 type FileNameWithInfo struct {
17 Type []byte // file type code
18 Creator []byte // File creator code
19 FileSize []byte // File Size in bytes
20 RSVD []byte
21 NameScript []byte // TODO: What is this?
22 NameSize []byte // Length of name field
23 Name []byte // File name
24 }
25
26 func (f FileNameWithInfo) Payload() []byte {
27 name := f.Name
28 nameSize := make([]byte, 2)
29 binary.BigEndian.PutUint16(nameSize, uint16(len(name)))
30
31 return concat.Slices(
32 f.Type,
33 f.Creator,
34 f.FileSize,
35 []byte{0, 0, 0, 0},
36 f.NameScript,
37 nameSize,
38 f.Name,
39 )
40 }
41
42 func (f *FileNameWithInfo) Read(p []byte) (n int, err error) {
43 // TODO: check p for expected len
44 f.Type = p[0:4]
45 f.Creator = p[4:8]
46 f.FileSize = p[8:12]
47 f.RSVD = p[12:16]
48 f.NameScript = p[16:18]
49 f.NameSize = p[18:20]
50 f.Name = p[20:]
51
52 return len(p), err
53 }