Documentation ¶
Index ¶
- type CharReader
- type LineReader
- type Reader
- func (reader *Reader) AsTextReader() *TextReader
- func (reader *Reader) Close()
- func (reader *Reader) Count() (int, error)
- func (reader *Reader) EachChar(fn CharReader) error
- func (reader *Reader) EachImmutableLine(fn LineReader) error
- func (reader *Reader) EachLine(fn LineReader) error
- func (reader *Reader) Empty()
- func (reader *Reader) File() *os.File
- func (reader *Reader) Lines() ([][]byte, error)
- type TextLineReader
- type TextReader
- type TypedLineReader
- type TypedReader
- type Writer
- func (writer *Writer) AlwaysAppendNewLine() *Writer
- func (writer *Writer) Close()
- func (writer *Writer) End() error
- func (writer *Writer) Flush() error
- func (writer *Writer) Reset()
- func (writer *Writer) Write(t any) error
- func (writer *Writer) WriteMarshal(marshaller paopao.Marshaller, t any) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CharReader ¶ added in v1.0.6
type CharReader func(char rune)
type LineReader ¶
type LineReader func(line []byte)
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
func (*Reader) AsTextReader ¶
func (reader *Reader) AsTextReader() *TextReader
AsTextReader converts a Reader into a TextReader.
func (*Reader) Close ¶
func (reader *Reader) Close()
Close will abruptly close the underlying io.Reader, this is not needed in most cases as all the methods in the Reader will close the io.Reader upon completion of the action.
func (*Reader) Count ¶
Count will count all the lines of the file. Internally, this uses Lines and will exhaust the underlying io.Reader which means that the reader will no longer be usable, but unless the cache is dereferenced, you can retrieve all the lines using the Lines method afterward.
func (*Reader) EachChar ¶ added in v1.0.6
func (reader *Reader) EachChar(fn CharReader) error
EachChar reads each char of the file. Unlike EachLine, this will do a char-by-char process, which means everything including next line characters will be included.
func (*Reader) EachImmutableLine ¶
func (reader *Reader) EachImmutableLine(fn LineReader) error
EachImmutableLine reads each line of the file as bytes. Unlike EachLine, there is copying involved which makes this slower than the other, but the byte array here won't be overridden each line, allowing you to store the byte array elsewhere without extra copying.
func (*Reader) EachLine ¶
func (reader *Reader) EachLine(fn LineReader) error
EachLine reads each line of the file as bytes. Unlike EachImmutableLine, the byte array is reused which means it will be overridden each next line, therefore, it is not recommended to store the byte array elsewhere without copying.
func (*Reader) Empty ¶
func (reader *Reader) Empty()
Empty dereferences the cache of the reader, if any. A cache will be added when methods such as Count or Lines are used as it empties the underlying io.Reader, therefore, if you don't want the cache then it is recommended to dereference it.
func (*Reader) Lines ¶
Lines returns all the lines of the file, this references the cache if there is any, otherwise loads the file and saves the array into the cache. To dereference the cache, simply use the Empty method. Note that this will exhaust the underlying io.Reader which means that the reader will no longer be usable.
type TextLineReader ¶
type TextLineReader func(line string)
type TextReader ¶
type TextReader struct {
// contains filtered or unexported fields
}
func (*TextReader) Count ¶
func (reader *TextReader) Count() (int, error)
Count will count all the lines of the file. Internally, this uses Lines and will exhaust the underlying io.Reader which means that the reader will no longer be usable, but unless the cache is dereferenced, you can retrieve all the lines using the Lines method afterward.
func (*TextReader) EachChar ¶ added in v1.0.6
func (reader *TextReader) EachChar(fn CharReader) error
EachChar reads each char of the file.
func (*TextReader) EachLine ¶
func (reader *TextReader) EachLine(fn TextLineReader) error
EachLine reads each line of the file as a string.
func (*TextReader) Empty ¶
func (reader *TextReader) Empty()
Empty dereferences the cache of the reader, if any. A cache will be added when methods such as Count or Lines are used as it empties the underlying io.Reader, therefore, if you don't want the cache then it is recommended to dereference it.
func (*TextReader) Lines ¶
func (reader *TextReader) Lines() ([]string, error)
Lines returns all the lines of the file, this references the cache if there is any, otherwise loads the file and saves the array into the cache. To dereference the cache, simply use the Empty method. Note that this will exhaust the underlying io.Reader which means that the reader will no longer be usable.
type TypedLineReader ¶
type TypedLineReader[T any] func(t *T)
type TypedReader ¶
type TypedReader[T any] struct { // contains filtered or unexported fields }
func NewTypedReader ¶
func NewTypedReader[T any](reader *Reader) *TypedReader[T]
NewTypedReader creates a TypedReader from a Reader instance, this uses the paopao.Unmarshal as its unmarshaler, to change the unmarshaler, use WithUnmarshaler.
func (*TypedReader[T]) EachLine ¶
func (reader *TypedReader[T]) EachLine(fn TypedLineReader[T]) error
EachLine reads each line and unmarshals it into the given type before performing the given function. Note that this will exhaust the underlying io.Reader which means that the reader becomes unusable after using this method.
func (*TypedReader[T]) Lines ¶
func (reader *TypedReader[T]) Lines() ([]T, error)
Lines will read each line and unmarshals it into the given type. Note that this will exhaust the underlying io.Reader which means that the reader becomes unusable after using this method.
func (*TypedReader[T]) WithUnmarshaler ¶
func (reader *TypedReader[T]) WithUnmarshaler(unmarshaler paopao.Unmarshaler)
WithUnmarshaler changes the unmarshaler of the typed reader, allowing you to change it to whichever other format that you prefer, or using an even faster unmarshaler.
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
func NewWriter ¶
NewWriter creates a new Writer from the given os.File, this creates a Writer with a buffer size of 4,096 bytes. If you want to create one with a different buffer size, use the NewWriterSize method instead.
func NewWriterSize ¶
NewWriterSize creates a new Writer from the given os.File with a given buffer size.
func (*Writer) AlwaysAppendNewLine ¶
AlwaysAppendNewLine will set the Writer to always append a new line for each write.
func (*Writer) Close ¶
func (writer *Writer) Close()
Close will abruptly close the underlying io.Writer of the Writer. IT IS NOT RECOMMENDED TO USE THIS, PLEASE USE End INSTEAD TO FLUSH AND CLOSE THE Writer.
func (*Writer) End ¶
End flushes the contents into the file before closing the underlying io.Writer.
func (*Writer) Flush ¶
Flush will flush all the buffered contents into the file. It is recommended to use this only when you want to push the contents of the file immediately, otherwise use End instead to flush and close the Writer.
func (*Writer) Reset ¶
func (writer *Writer) Reset()
Reset discards any unflushed buffered data, clears any error, and resets buffer to write its output to File. i.e. whatever the heck bufio.Writer's Reset method does.
func (*Writer) Write ¶
Write writes the content into the file, note that this does not append a new line for each write unless the Writer uses AlwaysAppendNewLine. This marshals anything other than string, bufio.Reader and byte array into the paopao.Marshal which is Json by default.
func (*Writer) WriteMarshal ¶
func (writer *Writer) WriteMarshal(marshaller paopao.Marshaller, t any) error
WriteMarshal marshals the content with the given marshaller. Note that string and byte array are also marshalled with the given marshaller.