func (m *MemS3Fs) Remove(name string) error {
	m.rlock()
	defer m.runlock()
	m.bucket().Del(name)
	if _, ok := m.getData()["name"]; ok {
		m.lock()
		delete(m.getData(), name)
		m.unlock()
	}
	return nil
}
Removes file immediately from both S3 and the local cache
package af3ro
import (
	"errors"
	"fmt"
	"os"
	"path"
	"path/filepath"
	"strings"
	"sync"
	"time"
	"github.com/goamz/goamz/aws"
	"github.com/goamz/goamz/s3"
	"github.com/spf13/afero"
)
var _ afero.Fs = new(MemS3Fs)
var mux = &sync.Mutex{}
type MemS3Fs struct {
	auth       aws.Auth
	region     aws.Region
	bucketName string
	data       map[string]afero.File
	mutex      *sync.RWMutex
}
func (m *MemS3Fs) lock() {
	mx := m.getMutex()
	mx.Lock()
}
func (m *MemS3Fs) unlock()  { m.getMutex().Unlock() }
func (m *MemS3Fs) rlock()   { m.getMutex().RLock() }
func (m *MemS3Fs) runlock() { m.getMutex().RUnlock() }
func (m *MemS3Fs) getData() map[string]afero.File {
	if m.data == nil {
		m.data = make(map[string]afero.File)
	}
	return m.data
}
func (m *MemS3Fs) getMutex() *sync.RWMutex {
	mux.Lock()
	if m.mutex == nil {
		m.mutex = &sync.RWMutex{}
	}
	mux.Unlock()
	return m.mutex
}
type MemDirMap map[string]afero.File
func (m MemDirMap) Len() int            { return len(m) }
func (m MemDirMap) Add(f afero.File)    { m[f.Name()] = f }
func (m MemDirMap) Remove(f afero.File) { delete(m, f.Name()) }
func (m MemDirMap) Files() (files []afero.File) {
	for _, f := range m {
		files = append(files, f)
	}
	return files
}
func (m MemDirMap) Names() (names []string) {
	for x := range m {
		names = append(names, x)
	}
	return names
}
func (MemS3Fs) Name() string { return "MemS3Fs: s3-backed memfs" }
func (m *MemS3Fs) Create(name string) (afero.File, error) {
	m.lock()
	m.getData()[name] = MemFileCreate(name, m.bucket())
	m.unlock()
	m.registerDirs(m.getData()[name])
	return m.getData()[name], nil
}
func (m *MemS3Fs) registerDirs(f afero.File) {
	var x = f.Name()
	for x != "/" {
		f := m.registerWithParent(f)
		if f == nil {
			break
		}
		x = f.Name()
	}
}
func (m *MemS3Fs) unRegisterWithParent(f afero.File) afero.File {
	parent := m.findParent(f)
	pmem := parent.(*InMemoryFile)
	pmem.memDir.Remove(f)
	return parent
}
func (m *MemS3Fs) findParent(f afero.File) afero.File {
	dirs, _ := path.Split(f.Name())
	if len(dirs) > 1 {
		_, parent := path.Split(path.Clean(dirs))
		if len(parent) > 0 {
			pfile, err := m.Open(parent)
			if err != nil {
				return pfile
			}
		}
	}
	return nil
}
func (m *MemS3Fs) registerWithParent(f afero.File) afero.File {
	if f == nil {
		return nil
	}
	parent := m.findParent(f)
	if parent != nil {
		pmem := parent.(*InMemoryFile)
		pmem.memDir.Add(f)
	} else {
		pdir := filepath.Dir(path.Clean(f.Name()))
		m.Mkdir(pdir, 0777)
	}
	return parent
}
func (m *MemS3Fs) Mkdir(name string, perm os.FileMode) error {
	m.rlock()
	d, ok := m.getData()[name]
	m.runlock()
	if ok {
		if imf, o := d.(*InMemoryFile); o && imf.memDir != nil {
			return nil
		}
		return afero.ErrFileExists
	} else {
		m.lock()
		m.getData()[name] = &InMemoryFile{name: name, memDir: &MemDirMap{}, dir: true}
		m.unlock()
		m.registerDirs(m.getData()[name])
	}
	return nil
}
func (m *MemS3Fs) MkdirAll(path string, perm os.FileMode) error {
	return m.Mkdir(path, 0777)
}
func (m *MemS3Fs) Open(name string) (afero.File, error) {
	m.rlock()
	f, ok := m.getData()[name]
	ff, ok := f.(*InMemoryFile)
	if ok {
		ff.Open()
	}
	m.runlock()
	if ok {
		return f, nil
	} else {
		return nil, afero.ErrFileNotFound
	}
}
func (m *MemS3Fs) OpenFile(name string, flag int, perm os.FileMode) (afero.File, error) {
	f, err := m.Open(name)
	if err != nil {
		return f, err
	}
	err = m.Chmod(f.Name(), perm)
	return f, err
}