1 // glocate -- ZFS-diff-friendly locate-like utility
2 // Copyright (C) 2022-2024 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/>.
24 "github.com/klauspost/compress/zstd"
27 func mustReadFull(r io.Reader, buf []byte) {
28 if _, err := io.ReadFull(r, buf); err != nil {
33 func reader(src io.Reader, sink chan Ent) {
34 comp, err := zstd.NewReader(src)
38 br := bufio.NewReaderSize(comp, 1<<17)
40 num := make([]byte, 8)
44 var depth, depthPrev uint8
46 _, err = io.ReadFull(br, num[:2])
53 nameLen = binary.BigEndian.Uint16(num[:2])
54 nameRaw := make([]byte, nameLen)
55 mustReadFull(br, nameRaw)
56 name := string(nameRaw)
57 mustReadFull(br, num[:1])
60 ent := Ent{mtime: int64(binary.BigEndian.Uint64(num))}
62 ent.size = int64(binary.BigEndian.Uint64(num))
63 if depth > depthPrev {
64 cols = append(cols, namePrev[:len(namePrev)-1])
65 } else if depth < depthPrev {
66 cols = cols[:len(cols)-int(depthPrev-depth)]
68 ent.name = append([]string{}, append(cols, name)...)