csv

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package csv 主要实现了stream/file的接口

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewInStream

func NewInStream(filename string) (file.InStream, error)

NewInStream 创建一个名为filename的csv输入流

func NewOutStream

func NewOutStream(filename string) (file.OutStream, error)

NewOutStream 创建一个名为filename的csv输出流

func NewRows

func NewRows(f *os.File, c *config.JSON) (file.Rows, error)

NewRows 通过文件句柄f,和配置文件c 创建行读取器

func NewWriter

func NewWriter(f *os.File, c *config.JSON) (file.StreamWriter, error)

NewWriter 通过文件句柄f,和配置文件c 创建csv流写入器

Types

type Column

type Column struct {
	Index  string `json:"index"`  // 索引 从1开始,代表第几列
	Type   string `json:"type"`   // 类型 bool bigInt decimal string time
	Format string `json:"format"` // joda时间格式
	// contains filtered or unexported fields
}

Column 列信息

type Creator

type Creator struct {
}

Creator csv输出流创建器

func (*Creator) Create

func (c *Creator) Create(filename string) (file.OutStream, error)

Create 创建一个名为filename的csv输出流

type InConfig

type InConfig struct {
	Columns    []Column `json:"column"`     // 列信息
	Encoding   string   `json:"encoding"`   // 编码
	Delimiter  string   `json:"delimiter"`  // 分割符
	NullFormat string   `json:"nullFormat"` // null文本
	StartRow   int      `json:"startRow"`   // 读取开始行数,从1开始
	Comment    string   `json:"comment"`    // 注释
	Compress   string   `json:"compress"`   // 压缩
}

InConfig csv配置

func NewInConfig

func NewInConfig(conf *config.JSON) (c *InConfig, err error)

NewInConfig 通过conf获取csv配置

type Opener

type Opener struct {
}

Opener csv输入流打开器

func (*Opener) Open

func (o *Opener) Open(filename string) (file.InStream, error)

Open 打开一个名为filename的csv输入流

type OutConfig

type OutConfig struct {
	Columns    []Column `json:"column"`     // 列信息
	Encoding   string   `json:"encoding"`   // 编码
	Delimiter  string   `json:"delimiter"`  // 分割符
	NullFormat string   `json:"nullFormat"` // null文本
	HasHeader  bool     `json:"hasHeader"`  // 是否有列头
	Header     []string `json:"header"`     // 列头
	Compress   string   `json:"compress"`   // 压缩
}

OutConfig csv配置

func NewOutConfig

func NewOutConfig(conf *config.JSON) (c *OutConfig, err error)

NewOutConfig 通过conf获取csv配置

type Rows

type Rows struct {
	// contains filtered or unexported fields
}

Rows 行读取器

func (*Rows) Close

func (r *Rows) Close() error

Close 关闭读文件流

func (*Rows) Error

func (r *Rows) Error() error

Error 读取中的错误

func (*Rows) Next

func (r *Rows) Next() bool

Next 是否有下一行

func (*Rows) Scan

func (r *Rows) Scan() (columns []element.Column, err error)

Scan 扫描成列

type Stream

type Stream struct {
	// contains filtered or unexported fields
}

Stream csv文件流

func (*Stream) Close

func (s *Stream) Close() (err error)

Close 关闭文件流

func (*Stream) Rows

func (s *Stream) Rows(conf *config.JSON) (rows file.Rows, err error)

Rows 新建一个配置未conf的csv行读取器

func (*Stream) Writer

func (s *Stream) Writer(conf *config.JSON) (file.StreamWriter, error)

Writer 新建一个配置未conf的csv流写入器

type Writer

type Writer struct {
	// contains filtered or unexported fields
}

Writer csv流写入器

func (*Writer) Close

func (w *Writer) Close() (err error)

Close 关闭

func (*Writer) Flush

func (w *Writer) Flush() (err error)

Flush 刷新至磁盘

func (*Writer) Write

func (w *Writer) Write(record element.Record) (err error)

Write 将记录record 写入csv文件

Jump to

Keyboard shortcuts

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