file

package
v0.0.0-...-2b10ca4 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBareQuote  = errors.New("bare \" in non-quoted-field")
	ErrQuote      = errors.New("extraneous or missing \" in quoted-field")
	ErrFieldCount = errors.New("wrong number of fields")

	// Deprecated: ErrTrailingComma is no longer used.
	ErrTrailingComma = errors.New("extra delimiter at end of line")
)

These are the errors that can be returned in [ParseError.Err].

Functions

func GetFileList

func GetFileList(dir string) ([]string, error)

获取文件夹下所有文件

func IsDir

func IsDir(dir string) bool

判断所有文件夹是否存在

func IsExists

func IsExists(name string) (bool, error)

判断文件或文件夹是否存在 如果是,返回 true,否则返回 false

func SplitFileByLines

func SplitFileByLines(inputFile string, linesPerFile int, addHeader, deleteSource bool) error

SplitFileByLines 按文件行数拆分文件 参数:

  • inputFile - 文件路径
  • linesPerFile - 每个文件的行数
  • addHeader - 是否添加文件头
  • deleteSource - 是否删除源文件

返回:

  • 错误信息

func SplitFileBySize

func SplitFileBySize(inputFile string, chunkSizeMB int, addHeader, deleteSource bool) error

SplitFileBySize 按文件大小拆分文件 参数:

  • inputFile - 文件路径
  • chunkSizeMB - 每个文件的大小(单位 MB)
  • addHeader - 是否添加文件头
  • deleteSource - 是否删除源文件

返回:

  • 错误信息

Types

type ParseError

type ParseError struct {
	StartLine int   // Line where the record starts
	Line      int   // Line where the error occurred
	Column    int   // Column (1-based byte index) where the error occurred
	Err       error // The actual error
}

A ParseError is returned for parsing errors. Line and column numbers are 1-indexed.

func (*ParseError) Error

func (e *ParseError) Error() string

func (*ParseError) Unwrap

func (e *ParseError) Unwrap() error

type Reader

type Reader struct {
	Escape byte

	Comma string

	Comment rune

	FieldsPerRecord int

	LazyQuotes bool

	TrimLeadingSpace bool

	ReuseRecord bool

	TrailingComma bool
	// contains filtered or unexported fields
}

func NewReader

func NewReader(r io.Reader, sep string, escape byte) *Reader

NewReader returns a new Reader that reads from r.

func (*Reader) FieldPos

func (r *Reader) FieldPos(field int) (line, column int)

func (*Reader) IndexByte

func (r *Reader) IndexByte(s []byte, c byte) int

func (*Reader) InputOffset

func (r *Reader) InputOffset() int64

func (*Reader) Read

func (r *Reader) Read() (record []string, err error)

func (*Reader) ReadAll

func (r *Reader) ReadAll() (records [][]string, err error)

type Writer

type Writer struct {
	Comma   string // Field delimiter (set to ',' by NewWriter)
	UseCRLF bool   // True to use \r\n as the line terminator
	// contains filtered or unexported fields
}

func NewWriter

func NewWriter(w io.Writer, seq string, useQuote bool, escape byte) *Writer

NewWriter returns a new Writer that writes to w.

func (*Writer) Flush

func (w *Writer) Flush() error

func (*Writer) Write

func (w *Writer) Write(record []string) error

func (*Writer) WriteAll

func (w *Writer) WriteAll(records [][]string) error

Jump to

Keyboard shortcuts

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