Documentation
¶
Overview ¶
Package document decodes documents and loads, saves, and checks local files.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrConflict = errors.New("document: file changed on disk") ErrUnsupported = errors.New("document: unsupported encoding") ErrNotText = errors.New("document: not a text file") ErrReadOnly = errors.New("document: read-only file") ErrLossy = errors.New("document: reopen with an encoding that decodes the original bytes") )
Functions ¶
func ConvertIndent ¶
ConvertIndent converts each line's leading ASCII spaces and tabs, preserving the rest of the line and its ending. Tabs advance to the next source tab stop. When converting an all-space prefix to spaces, complete source indent levels are resized and any remaining spaces are kept. A nonpositive source size uses the target size. A nonpositive target size leaves the text unchanged.
func PrepareText ¶
func PrepareText(text string, o SaveOptions) string
PrepareText normalizes CRLF to LF and applies the requested text cleanup. Save uses the returned text before converting line endings and encoding it.
Types ¶
type Doc ¶
type Doc struct {
Path string
Kind Kind
Text string // LF-normalized for text and SVG documents.
Data []byte // Original bytes for images, nil for other kinds.
Width int // Image width in pixels, zero if unknown.
Height int // Image height in pixels, zero if unknown.
Animated bool // The image has multiple frames or declares animation.
Encoding Encoding
EOL EOL
Indent Indent
ReadOnly bool
Lossy bool // Text contains substitutions for undecodable bytes.
Stamp Stamp
}
Doc holds a loaded document. A Doc may only be mutated from one goroutine.
type File ¶
File encapsulates a path and its original access scope. A nil Workspace denotes a document the user explicitly opened outside workspace navigation.
func (File) Load ¶
func (f File) Load(o LoadOptions) (*Doc, error)
Load identifies and decodes the file within its original access scope.
type LoadOptions ¶
type LoadOptions struct {
Encoding Encoding // Empty to detect the encoding automatically.
Fallback Encoding // Used if there is no BOM and the bytes are invalid UTF-8.
MaxSize int64 // Zero uses the 256 MiB default. Recognized disk media bypass this limit.
ReadOnlyOver int64 // Zero uses the 20 MiB default.
}
LoadOptions controls text decoding and size limits for documents.
type SaveOptions ¶
type SaveOptions struct {
Context context.Context // Checked immediately before publishing a scoped write.
TrimTrailingSpace bool
FinalNewline bool
Force bool
Recreate bool // Publish only if the previous target is still absent.
SourceEncoding Encoding // Encoding used to read the existing buffer, if known.
}
SaveOptions controls text cleanup and the conditions for publishing a write.
type Stamp ¶
type Stamp struct {
Size int64
ModTime time.Time
Sum [32]byte
WorkspaceTarget string // Resolved relative workspace target for a scoped file.
// contains filtered or unexported fields
}
Stamp describes the file on disk. Sum is the SHA-256 of its original bytes, or zero if Load returned TooLarge, Video, or Audio.