mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-09-01 08:14:02 +03:00
Add in-memory file
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
package files
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"net"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type memFile struct {
|
||||
data string
|
||||
}
|
||||
|
||||
func (m memFile) Open(ctx context.Context) (io.ReadCloser, error) {
|
||||
return io.NopCloser(strings.NewReader(m.data)), nil
|
||||
}
|
||||
|
||||
func (m memFile) String() string {
|
||||
return "mem"
|
||||
}
|
||||
|
||||
func NewMem(networks []*net.IPNet) (File) {
|
||||
builder := strings.Builder{}
|
||||
|
||||
if len(networks) > 0 {
|
||||
builder.WriteString(networks[0].String())
|
||||
}
|
||||
|
||||
for i := 1; i < len(networks); i++ {
|
||||
builder.WriteString("\n")
|
||||
builder.WriteString(networks[i].String())
|
||||
}
|
||||
|
||||
return memFile{
|
||||
data: builder.String(),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user