mirror of
https://github.com/criyle/go-judge.git
synced 2025-11-04 14:50:02 +08:00
41 lines
735 B
Go
41 lines
735 B
Go
package file
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"io"
|
|
"io/ioutil"
|
|
)
|
|
|
|
var _ File = &memFile{}
|
|
|
|
// memFile represent a file like byte array
|
|
type memFile struct {
|
|
name string
|
|
content []byte
|
|
}
|
|
|
|
// NewMemFile create a file interface from content and content should not be modified afterwards
|
|
func NewMemFile(name string, content []byte) File {
|
|
return &memFile{
|
|
name: name,
|
|
content: content,
|
|
}
|
|
}
|
|
|
|
func (m *memFile) Name() string {
|
|
return m.name
|
|
}
|
|
|
|
func (m *memFile) Content() ([]byte, error) {
|
|
return m.content, nil
|
|
}
|
|
|
|
func (m *memFile) String() string {
|
|
return fmt.Sprintf("[memfile:%v,%d]", m.name, len(m.content))
|
|
}
|
|
|
|
func (m *memFile) Reader() (io.ReadCloser, error) {
|
|
return ioutil.NopCloser(bytes.NewReader(m.content)), nil
|
|
}
|