fork of go-git with some jj specific features
fork
Configure Feed
Select the types of activity you want to include in your feed.
1package sync
2
3import (
4 "bytes"
5 "compress/zlib"
6 "io"
7 "sync"
8)
9
10var (
11 zlibInitBytes = []byte{0x78, 0x9c, 0x01, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x01}
12 zlibReader = sync.Pool{
13 New: func() interface{} {
14 return NewZlibReader(nil)
15 },
16 }
17 zlibWriter = sync.Pool{
18 New: func() interface{} {
19 return zlib.NewWriter(nil)
20 },
21 }
22)
23
24type zlibReadCloser interface {
25 io.ReadCloser
26 zlib.Resetter
27}
28
29func NewZlibReader(dict *[]byte) ZLibReader {
30 r, _ := zlib.NewReader(bytes.NewReader(zlibInitBytes))
31 return ZLibReader{
32 Reader: r.(zlibReadCloser),
33 dict: dict,
34 }
35}
36
37type ZLibReader struct {
38 dict *[]byte
39 Reader zlibReadCloser
40}
41
42func (z ZLibReader) Reset(r io.Reader) error {
43 var dict []byte
44 if z.dict != nil {
45 dict = *z.dict
46 }
47 return z.Reader.Reset(r, dict)
48}
49
50// GetZlibReader returns a ZLibReader that is managed by a sync.Pool.
51// Returns a ZLibReader that is reset using a dictionary that is
52// also managed by a sync.Pool.
53//
54// After use, the ZLibReader should be put back into the sync.Pool
55// by calling PutZlibReader.
56func GetZlibReader(r io.Reader) (ZLibReader, error) {
57 z := zlibReader.Get().(ZLibReader)
58 z.dict = GetByteSlice()
59
60 err := z.Reader.Reset(r, *z.dict)
61
62 return z, err
63}
64
65// PutZlibReader puts z back into its sync.Pool, first closing the reader.
66// The Byte slice dictionary is also put back into its sync.Pool.
67func PutZlibReader(z ZLibReader) {
68 z.Reader.Close()
69 PutByteSlice(z.dict)
70 zlibReader.Put(z)
71}
72
73// GetZlibWriter returns a *zlib.Writer that is managed by a sync.Pool.
74// Returns a writer that is reset with w and ready for use.
75//
76// After use, the *zlib.Writer should be put back into the sync.Pool
77// by calling PutZlibWriter.
78func GetZlibWriter(w io.Writer) *zlib.Writer {
79 z := zlibWriter.Get().(*zlib.Writer)
80 z.Reset(w)
81 return z
82}
83
84// PutZlibWriter puts w back into its sync.Pool.
85func PutZlibWriter(w *zlib.Writer) {
86 zlibWriter.Put(w)
87}