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 mustWrite(w io.Writer, buf []byte) {
30 if _, err := w.Write(buf); err != nil {
35 func writer(dst io.Writer, sink chan Ent) {
36 comp, err := zstd.NewWriter(dst)
40 bw := bufio.NewWriterSize(comp, 1<<17)
41 num := make([]byte, 8)
43 for ent := range sink {
44 name = ent.name[len(ent.name)-1]
45 if len(ent.name) >= 1<<16 {
48 binary.BigEndian.PutUint16(num[:2], uint16(len(name)))
49 mustWrite(bw, num[:2])
50 mustWrite(bw, []byte(name))
51 if len(ent.name) >= 1<<8 {
54 mustWrite(bw, []byte{byte(len(ent.name) - 1)})
55 binary.BigEndian.PutUint64(num, uint64(ent.mtime))
57 binary.BigEndian.PutUint64(num, uint64(ent.size))
60 if err = bw.Flush(); err != nil {
63 if err = comp.Close(); err != nil {