mirror of
https://github.com/foxcpp/maddy.git
synced 2025-04-06 14:37:37 +03:00
Extract several packages to form a public API
This commit is contained in:
parent
7d497f88f0
commit
bcceec4fe4
170 changed files with 385 additions and 392 deletions
33
framework/buffer/memory.go
Normal file
33
framework/buffer/memory.go
Normal file
|
@ -0,0 +1,33 @@
|
|||
package buffer
|
||||
|
||||
import (
|
||||
"io"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
// MemoryBuffer implements Buffer interface using byte slice.
|
||||
type MemoryBuffer struct {
|
||||
Slice []byte
|
||||
}
|
||||
|
||||
func (mb MemoryBuffer) Open() (io.ReadCloser, error) {
|
||||
return NewBytesReader(mb.Slice), nil
|
||||
}
|
||||
|
||||
func (mb MemoryBuffer) Len() int {
|
||||
return len(mb.Slice)
|
||||
}
|
||||
|
||||
func (mb MemoryBuffer) Remove() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// BufferInMemory is a convenience function which creates MemoryBuffer with
|
||||
// contents of the passed io.Reader.
|
||||
func BufferInMemory(r io.Reader) (Buffer, error) {
|
||||
blob, err := ioutil.ReadAll(r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return MemoryBuffer{Slice: blob}, nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue