-
Notifications
You must be signed in to change notification settings - Fork 5.7k
/
noop.go
94 lines (71 loc) · 2.08 KB
/
noop.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Copyright 2020 PingCAP, Inc. Licensed under Apache-2.0.
package storage
import (
"context"
)
type noopStorage struct{}
// DeleteFile delete the file in storage
func (*noopStorage) DeleteFile(_ context.Context, _ string) error {
return nil
}
// DeleteFiles deletes the files in storage
func (*noopStorage) DeleteFiles(_ context.Context, _ []string) error {
return nil
}
// WriteFile file to storage.
func (*noopStorage) WriteFile(_ context.Context, _ string, _ []byte) error {
return nil
}
// ReadFile storage file.
func (*noopStorage) ReadFile(_ context.Context, _ string) ([]byte, error) {
return []byte{}, nil
}
// FileExists return true if file exists.
func (*noopStorage) FileExists(_ context.Context, _ string) (bool, error) {
return false, nil
}
// Open a Reader by file path.
func (*noopStorage) Open(_ context.Context, _ string, _ *ReaderOption) (ExternalFileReader, error) {
return noopReader{}, nil
}
// WalkDir traverse all the files in a dir.
func (*noopStorage) WalkDir(_ context.Context, _ *WalkOption, _ func(string, int64) error) error {
return nil
}
func (*noopStorage) URI() string {
return "noop:///"
}
// Create implements ExternalStorage interface.
func (*noopStorage) Create(_ context.Context, _ string, _ *WriterOption) (ExternalFileWriter, error) {
return &NoopWriter{}, nil
}
// Rename implements ExternalStorage interface.
func (*noopStorage) Rename(_ context.Context, _, _ string) error {
return nil
}
// Close implements ExternalStorage interface.
func (*noopStorage) Close() {}
func newNoopStorage() *noopStorage {
return &noopStorage{}
}
type noopReader struct{}
func (noopReader) Read(p []byte) (n int, err error) {
return len(p), nil
}
func (noopReader) Close() error {
return nil
}
func (noopReader) Seek(offset int64, _ int) (int64, error) {
return offset, nil
}
func (noopReader) GetFileSize() (int64, error) {
return 0, nil
}
// NoopWriter is a writer that does nothing.
type NoopWriter struct{}
func (NoopWriter) Write(_ context.Context, p []byte) (int, error) {
return len(p), nil
}
func (NoopWriter) Close(_ context.Context) error {
return nil
}