github.com/readium/readium-lcp-server@v0.0.0-20240101192032-6e95190e99f1/storage/nostore.go (about) 1 // Copyright (c) 2022 Readium Foundation 2 // Use of this source code is governed by a BSD-style license 3 // that can be found in the LICENSE file exposed on Github (readium) in the project repository. 4 5 package storage 6 7 import ( 8 "io" 9 ) 10 11 // void storage, created to avoid breaking interfaces in case the storage is handled by the encryption tool. 12 13 type noStorage struct { 14 } 15 16 type noItem struct { 17 name string 18 } 19 20 // noItem functions 21 22 func (i noItem) Key() string { 23 return i.name 24 } 25 26 func (i noItem) PublicURL() string { 27 return "" 28 } 29 30 func (i noItem) Contents() (io.ReadCloser, error) { 31 return nil, ErrNotFound 32 } 33 34 // noStorage functions 35 36 func (s noStorage) Add(key string, r io.ReadSeeker) (Item, error) { 37 return &noItem{name: key}, nil 38 } 39 40 func (s noStorage) Get(key string) (Item, error) { 41 return nil, ErrNotFound 42 } 43 44 func (s noStorage) Remove(key string) error { 45 return ErrNotFound 46 } 47 48 func (s noStorage) List() ([]Item, error) { 49 return nil, ErrNotFound 50 } 51 52 // NoStorage creates a new void storage 53 // 54 func NoStorage() Store { 55 return noStorage{} 56 }