12 const pathSeparator = "/" // File path separator TODO: make configurable to support Windows
14 // FilePathItem represents the file or directory portion of a delimited file path (e.g. foo and bar in "/foo/bar")
17 // 73 75 62 66 6f 6c 64 65 72 // "subfolder"
18 type FilePathItem struct {
23 type FilePath struct {
28 func (fp *FilePath) UnmarshalBinary(b []byte) error {
29 reader := bytes.NewReader(b)
30 err := binary.Read(reader, binary.BigEndian, &fp.ItemCount)
31 if err != nil && !errors.Is(err, io.EOF) {
34 if errors.Is(err, io.EOF) {
38 for i := uint16(0); i < fp.Len(); i++ {
39 // skip two bytes for the file path delimiter
40 _, _ = reader.Seek(2, io.SeekCurrent)
42 // read the length of the next pathItem
43 segLen, err := reader.ReadByte()
48 pBytes := make([]byte, segLen)
50 _, err = reader.Read(pBytes)
51 if err != nil && !errors.Is(err, io.EOF) {
55 fp.Items = append(fp.Items, FilePathItem{Len: segLen, Name: pBytes})
61 func (fp *FilePath) IsDropbox() bool {
66 return strings.Contains(strings.ToLower(string(fp.Items[fp.Len()-1].Name)), "drop box")
69 func (fp *FilePath) IsUploadDir() bool {
74 return strings.Contains(strings.ToLower(string(fp.Items[fp.Len()-1].Name)), "upload")
77 func (fp *FilePath) Len() uint16 {
78 return binary.BigEndian.Uint16(fp.ItemCount[:])
81 func (fp *FilePath) String() string {
83 for _, i := range fp.Items {
84 out = append(out, string(i.Name))
87 return path.Join(out...)
90 func readPath(fileRoot string, filePath, fileName []byte) (fullPath string, err error) {
93 if err = fp.UnmarshalBinary(filePath); err != nil {
102 path.Join("/", string(fileName)),