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