- pathData := b[2:]
- for i := uint16(0); i < fp.Len(); i++ {
- segLen := pathData[2]
- fp.Items = append(fp.Items, NewFilePathItem(pathData[:segLen+3]))
- pathData = pathData[3+segLen:]
+ scanner := bufio.NewScanner(reader)
+ scanner.Split(fileItemScanner)
+
+ for i := 0; i < int(binary.BigEndian.Uint16(fp.ItemCount[:])); i++ {
+ var fpi FilePathItem
+ scanner.Scan()
+
+ // Make a new []byte slice and copy the scanner bytes to it. This is critical to avoid a data race as the
+ // scanner re-uses the buffer for subsequent scans.
+ buf := make([]byte, len(scanner.Bytes()))
+ copy(buf, scanner.Bytes())
+
+ if _, err := fpi.Write(buf); err != nil {
+ return n, err
+ }
+ fp.Items = append(fp.Items, fpi)