filesplit

package module
v0.0.0-...-bccee9a Latest Latest
Warning

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

Go to latest
Published: May 21, 2020 License: MIT Imports: 4 Imported by: 0

README

Filesplit

A simple way to do files of a given line count

Installation

go get -u github.com/hmschreck/filesplit

How to use

import "github.com/hmschreck/filesplit"

...
fs := filesplit.FileSplitter{
  Pattern: "something-%d.csv",
  MaxLines: 1000,
}

fs.Start()

You can now write to the proper rollover file by using the Write method of fs

CSVs

There is a specific implementation for CSV files.

fs := filesplit.FileSplitter{
  Pattern: "something-%d.csv",
  MaxLines: 1000,
}

fs.Start()
fs.CsvStart()

fs.CsvWriter([]string) is now an automatic rollover when there are too many lines.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var HandlePermissions = os.O_TRUNC | os.O_CREATE
View Source
var Permissions = os.FileMode(0644)

Functions

This section is empty.

Types

type FileSplitter

type FileSplitter struct {
	Initialized        bool
	MaxLines           int
	CurrentLinesInFile int
	CurrentOffset      int
	CurrentFile        *os.File
	Pattern            string
	CSVWriter          *csv.Writer
}

func (*FileSplitter) Close

func (fs *FileSplitter) Close() (err error)

func (*FileSplitter) CsvStart

func (fs *FileSplitter) CsvStart()

func (*FileSplitter) CsvWriter

func (fs *FileSplitter) CsvWriter(record []string)

func (*FileSplitter) GetFilename

func (fs *FileSplitter) GetFilename() (filename string, err error)

func (*FileSplitter) Rollover

func (fs *FileSplitter) Rollover() (err error)

func (*FileSplitter) ShowFilename

func (fs *FileSplitter) ShowFilename()

func (*FileSplitter) Start

func (fs *FileSplitter) Start() (err error)

func (*FileSplitter) Write

func (fs *FileSplitter) Write(input []byte) (n int, err error)

Jump to

Keyboard shortcuts

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