11 const pathSeparator = "/" // File path separator TODO: make configurable to support Windows
13 // FilePathItem represents the file or directory portion of a delimited file path (e.g. foo and bar in "/foo/bar")
16 // 73 75 62 66 6f 6c 64 65 72 // "subfolder"
17 type FilePathItem struct {
22 func NewFilePathItem(b []byte) FilePathItem {
29 type FilePath struct {
34 const minFilePathLen = 2
36 func (fp *FilePath) UnmarshalBinary(b []byte) error {
40 if len(b) < minFilePathLen {
41 return errors.New("insufficient bytes")
43 err := binary.Read(bytes.NewReader(b[0:2]), binary.BigEndian, &fp.ItemCount)
49 for i := uint16(0); i < fp.Len(); i++ {
51 fp.Items = append(fp.Items, NewFilePathItem(pathData[:segLen+3]))
52 pathData = pathData[3+segLen:]
58 func (fp *FilePath) IsDropbox() bool {
63 return strings.Contains(strings.ToLower(string(fp.Items[fp.Len()-1].Name)), "drop box")
66 func (fp *FilePath) IsUploadDir() bool {
71 return strings.Contains(strings.ToLower(string(fp.Items[fp.Len()-1].Name)), "upload")
74 func (fp *FilePath) Len() uint16 {
75 return binary.BigEndian.Uint16(fp.ItemCount[:])
78 func (fp *FilePath) String() string {
80 for _, i := range fp.Items {
81 out = append(out, string(i.Name))
84 return path.Join(out...)
87 func ReadFilePath(filePathFieldData []byte) string {
89 err := fp.UnmarshalBinary(filePathFieldData)
96 func readPath(fileRoot string, filePath, fileName []byte) (fullPath string, err error) {
99 if err = fp.UnmarshalBinary(filePath); err != nil {
104 fullPath = path.Join(
108 path.Join("/", string(fileName)),