Documentation
¶
Index ¶
- type Content
- func (receiver *Content) Close() error
- func (receiver *Content) Closed() bool
- func (*Content) IsDir() bool
- func (receiver *Content) Read(p []byte) (int, error)
- func (receiver *Content) Seek(offset int64, whence int) (int64, error)
- func (receiver *Content) Size() int64
- func (receiver *Content) String() string
- type RegularFile
- func (receiver *RegularFile) Close() error
- func (receiver *RegularFile) Closed() bool
- func (receiver *RegularFile) Info() (fs.FileInfo, error)
- func (receiver *RegularFile) IsDir() bool
- func (receiver *RegularFile) Name() string
- func (receiver *RegularFile) Read(p []byte) (int, error)
- func (receiver *RegularFile) Seek(offset int64, whence int) (int64, error)
- func (receiver *RegularFile) Stat() (fs.FileInfo, error)
- func (receiver *RegularFile) String() string
- func (RegularFile) Type() fs.FileMode
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 that also implements io.Seeker.
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) Closed ¶
func (receiver *RegularFile) Closed() bool
Closed returns whether a strfs.RegularFile is closed or not.
func (*RegularFile) IsDir ¶
func (receiver *RegularFile) IsDir() bool
func (*RegularFile) Name ¶
func (receiver *RegularFile) Name() string
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'}
func (*RegularFile) Seek ¶
func (receiver *RegularFile) Seek(offset int64, whence int) (int64, error)
func (*RegularFile) Stat ¶
func (receiver *RegularFile) Stat() (fs.FileInfo, error)
Stat returns a fs.FileInfo for a *strfs.RegularFile.
Stat helps strfs.RegularFile fit the fs.File interface.
func (*RegularFile) String ¶
func (receiver *RegularFile) String() string
String returns the value of the string that strfs.RegularFile is wrapping.
String makes *strfs.RegularFile fit the fmt.Stringer interface.
func (RegularFile) Type ¶
func (RegularFile) Type() fs.FileMode