go-ethereum/statediff/indexer/database/file/test_helpers.go
2021-11-20 12:25:12 -06:00

29 lines
501 B
Go

package file
import "io"
type MemWriter struct {
bytes []byte
}
func NewMemWriter() io.WriteCloser {
return &MemWriter{}
}
// Write satisfies io.WriteCloser
func (mw *MemWriter) Write(b []byte) (int, error) {
mw.bytes = append(mw.bytes, b...)
return len(b), nil
}
// Close satisfies io.WriteCloser
func (mw *MemWriter) Close() error {
mw.bytes = []byte{}
return nil
}
// ReadAll returns all the bytes written to the memory writer
func (mw *MemWriter) ReadAll() []byte {
return mw.bytes
}