view

package
v0.1.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 21, 2026 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Render

func Render(s *Source, f Format, opts *Options) error

Render 按 Format 分发到具体渲染器,输出到 stdout。

func SniffContentType

func SniffContentType(s *Source) error

SniffContentType 读取前 512 字节,经 net/http.DetectContentType 判定 MIME, 再用 io.MultiReader 拼回,确保不丢数据。仅当 ContentType 为空时调用。

Types

type Format

type Format int

Format 表示渲染目标的格式。

const (
	FormatAuto Format = iota // 按扩展名→ContentType→嗅探→Binary 自动判定
	FormatText
	FormatJSON
	FormatYAML
	FormatCSV
	FormatXML
	FormatImage
	FormatBinary
)

func DetectFormat

func DetectFormat(s *Source) Format

DetectFormat 按优先级判定格式:扩展名 > ContentType(可能触发嗅探)> Binary。

func ParseFormat

func ParseFormat(name string) (Format, bool)

ParseFormat 将 --as flag 的值解析为 Format。

type Options

type Options struct {
	Force         bool  // 跳过大小限制
	MaxImageBytes int64 // 图片最大字节数,超出提示 --force
	Width         int   // 字符画列宽,0=自动探测
}

Options 控制渲染行为。

type Source

type Source struct {
	Reader      io.ReadCloser
	Size        int64  // -1 表示未知(S3 无 Content-Length 时)
	ContentType string // S3 resp.ContentType / 嗅探结果
	Name        string // 本地 filepath.Base / S3 s3path.BaseName(key)
	IsS3        bool
}

Source 是统一的渲染数据源:来自 S3 对象或本地文件,均暴露 io.ReadCloser。

func OpenSource

func OpenSource(ctx context.Context, arg string, s3c *s3.Client, defaultBucket string) (*Source, error)

OpenSource 按 scheme 分发:s3:// → S3 GetObject 直读(不用 manager.Downloader, 避免 checksum-trailer 与服务端不兼容);否则 → os.Open + os.Stat。 s3c 在本地路径时可为 nil。defaultBucket 在 s3:///key(空桶段)时填充为配置默认桶。

func OpenSourceRange added in v0.0.8

func OpenSourceRange(ctx context.Context, arg string, s3c *s3.Client, defaultBucket, rng string) (*Source, error)

OpenSourceRange 与 OpenSource 相同,但通过 Range 只读尾部窗口(仅支持 "bytes=-N" 后缀语义)。 S3 分支走 GetObject Range;本地分支按 Size-N Seek。rng 为空时等价 OpenSource。

func (*Source) Close

func (s *Source) Close() error

Close 关闭底层 reader。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL