Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Content ¶
type Content struct {
// contains filtered or unexported fields
}
Content represents the content part of a file.
Content does NOT map to anything in Go's built-in "fs" package.
But, for example, is used to create a RegularFile (which maps to a fs.File).
Example usage:
var content strfs.Content = strfs.CreateContent("<!DOCTYPE html>"+"\n"+"<html></html>") var regularfile strfs.RegularFile = strfs.RegularFile{ FileContent: content, FileName: "notice.html", FileModTime: time.Date(2022, 12, 12, 10, 30, 14, 2, time.UTC), }
func CreateContent ¶
CreateContent returns a strfs.Content whose content is the string given to it.
Example usage:
var content strfs.Content = strfs.CreateContent("# Hello world!"+"\r\r"+"Welcome to my document."+"\n") var regularfile strfs.RegularFile = strfs.RegularFile{ FileContent: content, FileName: "message.md", FileModTime: time.Now(), }
func EmptyContent ¶
func EmptyContent() Content
EmptyContent is used to see if a given strfs.Content is empty.
Note that a strfs.Content being empty is NOT the same as containing the empty string!
A strfs.Content is empty when it hasn't been initialized.
Example usage:
var content strfs.Content // ... if strfs.EmptyContent() == content { //@TODO }
func (*Content) Close ¶
Close will stop the Read method from working.
Close can safely be called more than once.
Close makes strfs.Content fit the io.Closer interface.
func (*Content) Read ¶
Read reads up to len(p) bytes into 'p'. Read returns the number of bytes actually read, and any errors it encountered.
Read makes strfs.Content fit the io.Reader interface.
Example usage:
var content strfs.Content = strfs.CreateContent("ABCDEFGHIJKLMNOPQRSTUVWXYZ") var b1 [5]byte var p1 []byte = b1[:] n, err := content.Read(p1) // n == 5 // b1 == [5]byte{'A', 'B', 'C', 'D', 'E'} // ... var b2 [4]byte var p2 []byte = b2[:] n, err := content.Read(p2) // n == 4 // b2 == [5]byte{'F', 'G', 'H', 'I'}
type RegularFile ¶
RegularFile lets you turn a string into a fs.File.
Example usage:
var content strfs.Content = strfs.CreateContent("<!DOCTYPE html>"+"\n"+"<html><body>Hello world!</body></html>") var regularfile strfs.RegularFile = strfs.RegularFile{ FileContent: content, FileName: "helloworld.html", FileModTime: time.Date(2022, 12, 12, 10, 30, 14, 2, time.UTC), }
func (*RegularFile) Close ¶
func (receiver *RegularFile) Close() error
Close will stop the Read method from working.
Close can safely be called more than once.
Close helps strfs.RegularFile fit the fs.File interface. Close makes strfs.RegularFile fit the io.Closer interface.
func (*RegularFile) Read ¶
func (receiver *RegularFile) Read(p []byte) (int, error)
Read reads up to len(p) bytes into 'p'. Read returns the number of bytes actually read, and any errors it encountered.
Read helps strfs.RegularFile fit the fs.File interface. Read makes strfs.Content fit the io.Reader interface.
Example usage:
var content strfs.Content = strfs.CreateContent("ABCDEFGHIJKLMNOPQRSTUVWXYZ") var regularfile strfs.RegularFile = strfs.RegularFile{ FileContent: content, FileName: "alphabet.txt", FileModTime: time.Now(), } var b1 [5]byte var p1 []byte = b1[:] n, err := regularfile.Read(p1) // n == 5 // b1 == [5]byte{'A', 'B', 'C', 'D', 'E'} // ... var b2 [4]byte var p2 []byte = b2[:] n, err := regularfile.Read(p2) // n == 4 // b2 == [5]byte{'F', 'G', 'H', 'I'}