file

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

README

Developer Guide for Class Two-Dimensional Table File Storage

Class Two-Dimensional Table File Storage is a framework that abstracts the flow of class two-dimensional table files. This framework can support reading and writing various class two-dimensional table file formats.

Input File Stream

// Opener is an interface for an opener that can open an input stream
type Opener interface {
 Open(filename string) (stream InStream, err error) // Open an input stream with the filename
}

// InStream is an interface for an input stream
type InStream interface {
 Rows(conf *config.JSON) (rows Rows, err error) // Get a row reader
 Close() (err error)                            // Close the input stream
}

// Rows is an interface for a row reader
type Rows interface {
 Next() bool                                  // Get the next row, return false if there is no next row, true if there is
 Scan() (columns []element.Column, err error) // Scan each row's columns
 Error() error                                // Get the error of the next row
 Close() error                                // Close the row reader
}

The InStream input stream can obtain a row reader Rows by passing in a JSON configuration file, which converts a row of data into a record in Rows. For implementation details, refer to the csv package. Additionally, it is necessary to register the Opener.

func init() {
 var opener Opener
 file.RegisterOpener("csv", &opener)
}

Output File Stream

// Creator is an interface for a creator that can create an output stream
type Creator interface {
 Create(filename string) (stream OutStream, err error) // Create an output stream with the filename
}

// OutStream is an interface for an output stream
type OutStream interface {
 Writer(conf *config.JSON) (writer StreamWriter, err error) // Create a writer
 Close() (err error)                                        // Close the output stream
}

// StreamWriter is an interface for an output stream writer
type StreamWriter interface {
 Write(record element.Record) (err error) // Write a record
 Flush() (err error)                      // Flush to the file
 Close() (err error)                      // Close the output stream writer
}

The OutStream output stream can obtain an output stream writer StreamWriter by passing in a JSON configuration file, which converts a record into a row of data in StreamWriter. For implementation details, refer to the csv package. Additionally, it is necessary to register the Creator.

func init() {
 var creator Creator
 file.RegisterCreator("csv", &creator)
}

Documentation

Overview

Package file implements a framework for file input and output streams, which can be used for all types of two-dimensional table file input and output

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterCreator

func RegisterCreator(name string, creator Creator)

RegisterCreator - Registers an output stream creator with the given name 'name'.

func RegisterOpener

func RegisterOpener(name string, opener Opener)

RegisterOpener - Registers an input stream opener with the given name 'name'

func UnregisterAllCreater

func UnregisterAllCreater()

UnregisterAllCreater - Unregister all file openers.

func UnregisterAllOpener

func UnregisterAllOpener()

UnregisterAllOpener - Unregisters all file openers

Types

type Creator

type Creator interface {
	Create(filename string) (stream OutStream, err error) // Create an output stream named 'filename'.
}

Creator - The creator that generates the output stream.

type FetchHandler

type FetchHandler interface {
	OnRecord(element.Record) error         // Process Record - Handles the record
	CreateRecord() (element.Record, error) // Create Empty Record - Creates an empty record
}

FetchHandler - Acquires the record handler

type InStream

type InStream interface {
	Rows(conf *config.JSON) (rows Rows, err error) // Get Line Reader - Acquires a line reader
	Close() (err error)                            // Close Input Stream - Closes the input stream
}

InStream - Input stream

type InStreamer

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

InStreamer - Input stream wrapper

func NewInStreamer

func NewInStreamer(name string, filename string) (streamer *InStreamer, err error)

NewInStreamer - Opens an input stream named 'filename' using the input stream opener with the given 'name'

func (*InStreamer) Close

func (s *InStreamer) Close() error

Close - Closes the input stream

func (*InStreamer) Read

func (s *InStreamer) Read(ctx context.Context, conf *config.JSON, handler FetchHandler) (err error)

Read - Reads data using the record handler 'handler', context 'ctx', and configuration file 'conf'

type Opener

type Opener interface {
	Open(filename string) (stream InStream, err error) // Open Input Stream - Opens an input stream for the file named 'filename'
}

Opener - An opener used to open an input stream

type OutStream

type OutStream interface {
	Writer(conf *config.JSON) (writer StreamWriter, err error) // Create a writer for writing to the output stream.
	Close() (err error)                                        // Close the output stream.
}

OutStream - Represents the output stream.

type OutStreamer

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

OutStreamer - A wrapper for the output stream.

func NewOutStreamer

func NewOutStreamer(name string, filename string) (streamer *OutStreamer, err error)

NewOutStreamer - Opens an output stream named 'filename' using the creator with the given name 'name'.

func (*OutStreamer) Close

func (s *OutStreamer) Close() error

Close - Closes the writing wrapper.

func (*OutStreamer) Writer

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

Writer - Creates a stream writer based on the configuration 'conf'.

type Rows

type Rows interface {
	Next() bool                                  // Get Next Line - Returns true if there is a next line, false otherwise
	Scan() (columns []element.Column, err error) // Scan Columns - Scans the columns of each line
	Error() error                                // Get Error of Next Line - Gets the error of the next line
	Close() error                                // Close Line Reader - Closes the line reader
}

Rows - Line reader

type StreamWriter

type StreamWriter interface {
	Write(record element.Record) (err error) // Write a record to the output stream.
	Flush() (err error)                      // Flush the data to the file.
	Close() (err error)                      // Close the output stream writer.
}

StreamWriter - A writer for writing to the output stream.

Directories

Path Synopsis
Package compress mainly implements compression methods.
Package compress mainly implements compression methods.
Package csv mainly implements the stream/file interface.
Package csv mainly implements the stream/file interface.
Package xlsx mainly implements the stream/file interface.
Package xlsx mainly implements the stream/file interface.

Jump to

Keyboard shortcuts

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