Documentation
¶
Overview ¶
Package textread provides bounded UTF-8 line scanning for filesystem adapters with different consumer result policies.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func LineNumber ¶
LineNumber returns the one-based line attached to a scan failure, or zero when the failure is not line-specific.
func VisitLines ¶
func VisitLines(ctx context.Context, source io.Reader, limits Limits, visit func(number int, line []byte) error) error
VisitLines validates and normalizes a complete bounded input, then calls visit for each one-based line. The line slice is valid only until visit returns. A trailing newline contributes a final empty line, matching Scan's editor-facing line identity.
Types ¶
type Limits ¶
Limits define one complete UTF-8 line scan without prescribing what a consumer retains. InputBytes includes line separators and a UTF-8 BOM; LineBytes applies after BOM/CRLF normalization.
type Options ¶
type Options struct {
InputBytes int64
LineBytes int
OutputBytes int
StartLine int
MaxLines int
PartialLine bool
}
Options defines one complete scan. StartLine is zero-based, MaxLines zero means the rest of the file, and PartialLine permits the last selected line to be clipped at a UTF-8 boundary when the output budget is exhausted.
type Result ¶
type Result struct {
Content string
StartLine int
EndLine int
TotalLines int
Truncated bool
OutputTruncated bool
}
Result reports normalized LF text and the whole-file line count. StartLine is zero-based and EndLine is exclusive.
func Scan ¶
Scan validates and counts the complete admitted input while retaining only the selected output window.
Example ¶
package main
import (
"context"
"fmt"
"strings"
"github.com/Tangerg/scope/tools/textread"
)
func main() {
result, err := textread.Scan(context.Background(), strings.NewReader("zero\none\ntwo"), textread.Options{
InputBytes: 64, LineBytes: 16, OutputBytes: 64, StartLine: 1, MaxLines: 1,
})
if err != nil {
panic(err)
}
fmt.Println(result.Content, result.TotalLines)
}
Output: one 3