forked from vitessio/vitess
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fileutil.go
65 lines (51 loc) · 1.19 KB
/
fileutil.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright 2012, Google Inc. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package mysqlctl
import (
// "crypto/md5"
"encoding/hex"
"hash"
// "hash/crc64"
"os"
"github.com/youtube/vitess/go/cgzip"
)
// Use this to simulate failures in tests
var (
simulateFailures = false
failureCounter = 0
)
func init() {
_, statErr := os.Stat("/tmp/vtSimulateFetchFailures")
simulateFailures = statErr == nil
}
// our hasher, implemented using md5
// type hasher struct {
// hash.Hash
// }
// func newHasher() *hasher {
// return &hasher{md5.New()}
// }
// func (h *hasher) HashString() string {
// return hex.EncodeToString(h.Sum(nil))
// }
// our hasher, implemented using crc64
//type hasher struct {
// hash.Hash64
//}
//func newHasher() *hasher {
// return &hasher{crc64.New(crc64.MakeTable(crc64.ECMA))}
//}
//func (h *hasher) HashString() string {
// return hex.EncodeToString(h.Sum(nil))
//}
// our hasher, implemented using cgzip crc32
type hasher struct {
hash.Hash32
}
func newHasher() *hasher {
return &hasher{cgzip.NewCrc32()}
}
func (h *hasher) HashString() string {
return hex.EncodeToString(h.Sum(nil))
}