if set nil, then del

master
Bel LaPointe 2021-02-21 12:52:50 -06:00
parent e22f272906
commit 08dee901fa
1 changed files with 13 additions and 1 deletions

View File

@ -70,11 +70,23 @@ func (b *Files) Set(key string, value []byte, ns ...string) error {
log.Println("files.Set", ns, key, "to", len(value), value == nil)
r := bytes.NewReader(value)
if value == nil {
r = nil
return b.Del(key, ns...)
}
return b.SetStream(key, r, ns...)
}
func (b *Files) Del(key string, ns ...string) error {
log.Println("files.Del", ns, key)
namespace := resolve.Namespace(ns)
dir := path.Join(b.root, namespace)
path := path.Join(dir, key)
err := os.Remove(path)
if os.IsNotExist(err) {
err = nil
}
return err
}
func (b *Files) SetStream(key string, r io.Reader, ns ...string) error {
log.Println("files.SetStream", ns, key, "to", r, r == nil)
namespace := resolve.Namespace(ns)