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.
37 lines
892 B
Go
37 lines
892 B
Go
package gemini
|
|
|
|
import (
|
|
"gophi/core"
|
|
"os"
|
|
)
|
|
|
|
type headerPlusFileContent struct {
|
|
contents []byte
|
|
}
|
|
|
|
// WriteToClient writes the current contents of FileContents to the client
|
|
func (fc *headerPlusFileContent) WriteToClient(client *core.Client, p *core.Path) error {
|
|
return client.Conn().Write(fc.contents)
|
|
}
|
|
|
|
// Load takes an open FD and loads the file contents into FileContents memory
|
|
func (fc *headerPlusFileContent) Load(p *core.Path, file *os.File) error {
|
|
// Read the file contents
|
|
contents, err := core.ReadFile(file)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// Set sucess header + mime type response header
|
|
header := buildResponseHeader("20", getFileStatusMeta(p))
|
|
|
|
// Set the store contents and return ok
|
|
fc.contents = append(header, contents...)
|
|
return nil
|
|
}
|
|
|
|
// Clear empties currently cached FileContents memory
|
|
func (fc *headerPlusFileContent) Clear() {
|
|
fc.contents = nil
|
|
}
|