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 mustWrite(w io.Writer, buf []byte) {
28 if _, err := w.Write(buf); err != nil {
33 func writer(dst io.Writer, sink chan Ent) {
34 comp, err := zstd.NewWriter(dst)
38 bw := bufio.NewWriterSize(comp, 1<<17)
39 num := make([]byte, 8)
41 for ent := range sink {
42 name = ent.name[len(ent.name)-1]
43 if len(ent.name) >= 1<<16 {
46 binary.BigEndian.PutUint16(num[:2], uint16(len(name)))
47 mustWrite(bw, num[:2])
48 mustWrite(bw, []byte(name))
49 if len(ent.name) >= 1<<8 {
52 mustWrite(bw, []byte{byte(len(ent.name) - 1)})
53 binary.BigEndian.PutUint64(num, uint64(ent.mtime))
55 binary.BigEndian.PutUint64(num, uint64(ent.size))
58 if err = bw.Flush(); err != nil {
61 if err = comp.Close(); err != nil {