10 const pathSeparator = "/" // File path separator TODO: make configurable to support Windows
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 func NewFilePathItem(b []byte) FilePathItem {
28 type FilePath struct {
33 const minFilePathLen = 2
34 func (fp *FilePath) UnmarshalBinary(b []byte) error {
38 if len(b) < minFilePathLen {
39 return errors.New("insufficient bytes")
41 err := binary.Read(bytes.NewReader(b[0:2]), binary.BigEndian, &fp.ItemCount)
47 for i := uint16(0); i < fp.Len(); i++ {
49 fp.Items = append(fp.Items, NewFilePathItem(pathData[:segLen+3]))
50 pathData = pathData[3+segLen:]
56 func (fp *FilePath) Len() uint16 {
57 return binary.BigEndian.Uint16(fp.ItemCount[:])
60 func (fp *FilePath) String() string {
62 for _, i := range fp.Items {
63 out = append(out, string(i.Name))
66 return path.Join(out...)
69 func ReadFilePath(filePathFieldData []byte) string {
71 err := fp.UnmarshalBinary(filePathFieldData)
78 func readPath(fileRoot string, filePath, fileName []byte) (fullPath string, err error) {
81 if err = fp.UnmarshalBinary(filePath); err != nil {
90 path.Join("/", string(fileName)),