diff options
author | René 'Necoro' Neumann <necoro@necoro.eu> | 2021-02-27 22:26:34 +0100 |
---|---|---|
committer | René 'Necoro' Neumann <necoro@necoro.eu> | 2021-02-27 22:26:34 +0100 |
commit | f4ea0b4fca4fae270d785b84e9b105081826754f (patch) | |
tree | 79deeecf52872cfeaad45ba23d975e52f64c718b /internal/feed/cache/v2.go | |
parent | ae96e1bd2516ff2c70ad9dc010da84b7a03b9a35 (diff) | |
download | feed2imap-go-f4ea0b4fca4fae270d785b84e9b105081826754f.tar.gz feed2imap-go-f4ea0b4fca4fae270d785b84e9b105081826754f.tar.bz2 feed2imap-go-f4ea0b4fca4fae270d785b84e9b105081826754f.zip |
New cache format using gzip compression
Diffstat (limited to 'internal/feed/cache/v2.go')
-rw-r--r-- | internal/feed/cache/v2.go | 63 |
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() +} |