aboutsummaryrefslogtreecommitdiff
path: root/internal/feed/cache/v2.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/feed/cache/v2.go')
-rw-r--r--internal/feed/cache/v2.go63
1 files changed, 63 insertions, 0 deletions
diff --git a/internal/feed/cache/v2.go b/internal/feed/cache/v2.go
new file mode 100644
index 0000000..87636b6
--- /dev/null
+++ b/internal/feed/cache/v2.go
@@ -0,0 +1,63 @@
+package cache
+
+import (
+ "compress/gzip"
+ "fmt"
+ "io"
+
+ "github.com/Necoro/feed2imap-go/internal/feed"
+)
+
+const v2Version Version = 2
+
+// v2Cache is identical to v1Cache, but uses gzip compression for storage
+type v2Cache v1Cache
+
+func newV2Cache() *v2Cache {
+ return (*v2Cache)(newV1Cache())
+}
+
+func (cache *v2Cache) asV1() *v1Cache {
+ return (*v1Cache)(cache)
+}
+
+func (cache *v2Cache) cachedFeed(feed *feed.Feed) CachedFeed {
+ return cache.asV1().cachedFeed(feed)
+}
+
+func (cache *v2Cache) transformTo(v Version) (Impl, error) {
+ return nil, fmt.Errorf("Transformation not supported")
+}
+
+func (cache *v2Cache) Version() Version {
+ return v2Version
+}
+
+func (cache *v2Cache) Info() string {
+ return cache.asV1().Info()
+}
+
+func (cache *v2Cache) SpecificInfo(i interface{}) string {
+ return cache.asV1().SpecificInfo(i)
+}
+
+func (cache *v2Cache) load(reader io.Reader) error {
+ gzipReader, err := gzip.NewReader(reader)
+ if err != nil {
+ return err
+ }
+ defer gzipReader.Close()
+
+ return cache.asV1().load(gzipReader)
+}
+
+func (cache *v2Cache) store(writer io.Writer) error {
+ gzipWriter := gzip.NewWriter(writer)
+ defer gzipWriter.Close()
+
+ if err := cache.asV1().store(gzipWriter); err != nil {
+ return err
+ }
+
+ return gzipWriter.Flush()
+}