You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gophi/core/filecontent.go

35 lines
899 B
Go

package core
import (
"os"
)
// FileContent provides an interface for caching, rendering and getting cached contents of a file
type FileContent interface {
Load(*Path, *os.File) error
WriteToClient(*Client, *Path) error
Clear()
}
// RegularFileContent is the simplest implementation of core.FileContents for regular files
type RegularFileContent struct {
content []byte
}
// Load takes an open FD and loads the file contents into FileContents memory
func (fc *RegularFileContent) Load(p *Path, file *os.File) error {
var err error
fc.content, err = ReadFile(file)
return err
}
// WriteToClient writes the current contents of FileContents to the client
func (fc *RegularFileContent) WriteToClient(client *Client, p *Path) error {
return client.Conn().Write(fc.content)
}
// Clear empties currently cached FileContents memory
func (fc *RegularFileContent) Clear() {
fc.content = nil
}