forked from johannesboyne/gofakes3
-
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathtemp.go
More file actions
51 lines (39 loc) · 1.18 KB
/
temp.go
File metadata and controls
51 lines (39 loc) · 1.18 KB
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
package gofakes3
import (
"bytes"
"context"
"io"
)
type TempBlobFactory interface {
New(bucket, object string, partNumber int, size int64, expectedMD5 []byte) (TempBlob, error)
}
type TempBlob interface {
Reader(context.Context) io.ReadCloser
Writer(context.Context) io.WriteCloser
Cleanup(context.Context)
}
func newMemoryTempBlobFactory() TempBlobFactory {
return &memoryTempBlobFactory{}
}
type memoryTempBlobFactory struct{}
// New implements TempBlobFactory.
func (m *memoryTempBlobFactory) New(bucket, object string, partNumber int, size int64, epectedMD5 []byte) (TempBlob, error) {
return &memoryTempBlob{
buf: bytes.NewBuffer(make([]byte, 0, size)),
}, nil
}
type memoryTempBlob struct {
buf *bytes.Buffer
}
// Cleanup implements TempBlob.
func (m *memoryTempBlob) Cleanup(context.Context) {}
// Reader implements TempBlob.
func (m *memoryTempBlob) Reader(context.Context) io.ReadCloser {
return io.NopCloser(bytes.NewReader(m.buf.Bytes()))
}
// Writer implements TempBlob.
func (m *memoryTempBlob) Writer(context.Context) io.WriteCloser { return &nopWriteCloser{m.buf} }
type nopWriteCloser struct {
io.Writer
}
func (wc *nopWriteCloser) Close() error { return nil }