maddy

Fork https://github.com/foxcpp/maddy

git clone git://git.lin.moe/go/maddy.git

 1package imapsql
 2
 3import (
 4	"context"
 5	"io"
 6
 7	imapsql "github.com/foxcpp/go-imap-sql"
 8	"github.com/foxcpp/maddy/framework/module"
 9)
10
11type ExtBlob struct {
12	io.ReadCloser
13}
14
15func (e ExtBlob) Sync() error {
16	panic("not implemented")
17}
18
19func (e ExtBlob) Write(p []byte) (n int, err error) {
20	panic("not implemented")
21}
22
23type WriteExtBlob struct {
24	module.Blob
25}
26
27func (w WriteExtBlob) Read(p []byte) (n int, err error) {
28	panic("not implemented")
29}
30
31type ExtBlobStore struct {
32	Base module.BlobStore
33}
34
35func (e ExtBlobStore) Create(key string, objSize int64) (imapsql.ExtStoreObj, error) {
36	blob, err := e.Base.Create(context.TODO(), key, objSize)
37	if err != nil {
38		return nil, imapsql.ExternalError{
39			NonExistent: err == module.ErrNoSuchBlob,
40			Key:         key,
41			Err:         err,
42		}
43	}
44	return WriteExtBlob{Blob: blob}, nil
45}
46
47func (e ExtBlobStore) Open(key string) (imapsql.ExtStoreObj, error) {
48	blob, err := e.Base.Open(context.TODO(), key)
49	if err != nil {
50		return nil, imapsql.ExternalError{
51			NonExistent: err == module.ErrNoSuchBlob,
52			Key:         key,
53			Err:         err,
54		}
55	}
56	return ExtBlob{ReadCloser: blob}, nil
57}
58
59func (e ExtBlobStore) Delete(keys []string) error {
60	err := e.Base.Delete(context.TODO(), keys)
61	if err != nil {
62		return imapsql.ExternalError{
63			Key: "",
64			Err: err,
65		}
66	}
67	return nil
68}