aboutsummaryrefslogtreecommitdiff
path: root/connector/mediaobject.go
diff options
context:
space:
mode:
Diffstat (limited to 'connector/mediaobject.go')
-rw-r--r--connector/mediaobject.go50
1 files changed, 50 insertions, 0 deletions
diff --git a/connector/mediaobject.go b/connector/mediaobject.go
index a8d6f9a..244e571 100644
--- a/connector/mediaobject.go
+++ b/connector/mediaobject.go
@@ -132,3 +132,53 @@ type nullCloseReader struct {
func (ncr nullCloseReader) Close() error {
return nil
}
+
+// ----
+
+type LazyBlobMediaObject struct {
+ ObjectFilename string
+ ObjectMimetype string
+ ObjectImageSize *ImageSize
+ ObjectData []byte
+
+ GetFn func(o *LazyBlobMediaObject) error
+}
+
+func (m *LazyBlobMediaObject) Filename() string {
+ return m.ObjectFilename
+}
+
+func (m *LazyBlobMediaObject) Size() int64 {
+ if m.ObjectData == nil {
+ m.GetFn(m)
+ }
+ return int64(len(m.ObjectData))
+}
+
+func (m *LazyBlobMediaObject) Mimetype() string {
+ if m.ObjectData == nil {
+ m.GetFn(m)
+ }
+ return m.ObjectMimetype
+}
+
+func (m *LazyBlobMediaObject) ImageSize() *ImageSize {
+ if m.ObjectData == nil {
+ m.GetFn(m)
+ }
+ return m.ObjectImageSize
+}
+
+func (m *LazyBlobMediaObject) Read() (io.ReadCloser, error) {
+ if m.ObjectData == nil {
+ err := m.GetFn(m)
+ if err != nil {
+ return nil, err
+ }
+ }
+ return nullCloseReader{bytes.NewBuffer(m.ObjectData)}, nil
+}
+
+func (m *LazyBlobMediaObject) URL() string {
+ return ""
+}