12 // FilePathItem represents the file or directory portion of a delimited file path (e.g. foo and bar in "/foo/bar")
15 // 73 75 62 66 6f 6c 64 65 72 // "subfolder"
16 type FilePathItem struct {
21 type FilePath struct {
26 func (fp *FilePath) UnmarshalBinary(b []byte) error {
27 reader := bytes.NewReader(b)
28 err := binary.Read(reader, binary.BigEndian, &fp.ItemCount)
29 if err != nil && !errors.Is(err, io.EOF) {
32 if errors.Is(err, io.EOF) {
36 for i := uint16(0); i < fp.Len(); i++ {
37 // skip two bytes for the file path delimiter
38 _, _ = reader.Seek(2, io.SeekCurrent)
40 // read the length of the next pathItem
41 segLen, err := reader.ReadByte()
46 pBytes := make([]byte, segLen)
48 _, err = reader.Read(pBytes)
49 if err != nil && !errors.Is(err, io.EOF) {
53 fp.Items = append(fp.Items, FilePathItem{Len: segLen, Name: pBytes})
59 func (fp *FilePath) IsDropbox() bool {
64 return strings.Contains(strings.ToLower(string(fp.Items[fp.Len()-1].Name)), "drop box")
67 func (fp *FilePath) IsUploadDir() bool {
72 return strings.Contains(strings.ToLower(string(fp.Items[fp.Len()-1].Name)), "upload")
75 func (fp *FilePath) Len() uint16 {
76 return binary.BigEndian.Uint16(fp.ItemCount[:])
79 func (fp *FilePath) String() string {
81 for _, i := range fp.Items {
82 out = append(out, string(i.Name))
85 return filepath.Join(out...)
88 func readPath(fileRoot string, filePath, fileName []byte) (fullPath string, err error) {
91 if err = fp.UnmarshalBinary(filePath); err != nil {
96 fullPath = filepath.Join(
100 filepath.Join("/", string(fileName)),