1 // glocate -- ZFS-diff-friendly locate-like utility
2 // Copyright (C) 2022-2025 Sergey Matveev <stargrave@stargrave.org>
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, version 3 of the License.
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with this program. If not, see <http://www.gnu.org/licenses/>.
25 "github.com/klauspost/compress/zstd"
28 func mustReadFull(r io.Reader, buf []byte) {
29 if _, err := io.ReadFull(r, buf); err != nil {
34 func reader(src io.Reader, sink chan Ent) {
35 comp, err := zstd.NewReader(src)
39 br := bufio.NewReaderSize(comp, 1<<17)
41 num := make([]byte, 8)
45 var depth, depthPrev uint8
47 _, err = io.ReadFull(br, num[:2])
54 nameLen = binary.BigEndian.Uint16(num[:2])
55 nameRaw := make([]byte, nameLen)
56 mustReadFull(br, nameRaw)
57 name := string(nameRaw)
58 mustReadFull(br, num[:1])
61 ent := Ent{mtime: int64(binary.BigEndian.Uint64(num))}
63 ent.size = int64(binary.BigEndian.Uint64(num))
64 if depth > depthPrev {
65 cols = append(cols, namePrev[:len(namePrev)-1])
66 } else if depth < depthPrev {
67 cols = cols[:len(cols)-int(depthPrev-depth)]
69 ent.name = slices.Clone(append(cols, name))