xio

package
Version: v0.1.330 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2021 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AtomicDownload

func AtomicDownload(link, filename string) error

AtomicDownload retrieves a link and saves its content atomically in filename. TODO(martin): should live in an io related package.

func LoadSet

func LoadSet(r io.Reader, m map[string]struct{}) error

LoadSet reads the content of from a reader and creates a set from each line.

func ReadLines

func ReadLines(filename string) (lines []string, err error)

ReadLines returns a list of trimmed lines in a file. Empty lines are skipped.

func SetFromFilename

func SetFromFilename(filename string, m map[string]struct{}) error

SetFromFilename fills an initialized map as set with items from line in filename, with newlines stripped.

Types

type FileReader

type FileReader struct {
	Filename string
	// contains filtered or unexported fields
}

FileReader creates a ReadCloser from a filename. If postpones error handling up until the first read. TODO(miku): Throw this out.

func (*FileReader) Close

func (r *FileReader) Close() (err error)

Close closes the file.

func (*FileReader) Read

func (r *FileReader) Read(p []byte) (n int, err error)

Read reads from the file.

type LinkReader

type LinkReader struct {
	Link string
	// contains filtered or unexported fields
}

LinkReader implements io.Reader for a URL.

func (*LinkReader) Read

func (r *LinkReader) Read(p []byte) (int, error)

type ReaderCounter

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

ReaderCounter counts the number of bytes read.

func NewReaderCounter

func NewReaderCounter(r io.Reader) *ReaderCounter

NewReaderCounter function for create new ReaderCounter.

func (*ReaderCounter) Count

func (counter *ReaderCounter) Count() int64

Count function returns bytes read so far.

func (*ReaderCounter) Read

func (counter *ReaderCounter) Read(buf []byte) (int, error)

Read keeps count.

type SavedLink struct {
	Link string
	// contains filtered or unexported fields
}

SavedLink saves the content of a URL to a file.

func (*SavedLink) Remove

func (s *SavedLink) Remove()

Remove remove any left over temporary file.

func (*SavedLink) Save

func (s *SavedLink) Save() (filename string, err error)

Save link to a temporary file, return the filename.

type SavedReaders

type SavedReaders struct {
	Readers []io.Reader
	// contains filtered or unexported fields
}

SavedReaders takes a list of readers and persists their content in a temporary file.

func (*SavedReaders) Remove

func (r *SavedReaders) Remove()

Remove remove any left over temporary file.

func (*SavedReaders) Save

func (r *SavedReaders) Save() (filename string, err error)

Save saves all readers to a temporary file and returns the filename.

type SkipReader

type SkipReader struct {
	CommentPrefixes []string
	// contains filtered or unexported fields
}

SkipReader skips empty lines and lines with comments.

func NewSkipReader

func NewSkipReader(r *bufio.Reader) *SkipReader

NewSkipReader creates a new SkipReader.

func (SkipReader) ReadString

func (r SkipReader) ReadString(delim byte) (s string, err error)

ReadString will return only non-empty lines and lines not starting with a comment prefix.

type WriteCounter

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

WriteCounter counts the number of bytes written through it.

func (*WriteCounter) Count

func (w *WriteCounter) Count() uint64

Count returns the number of bytes written.

func (*WriteCounter) Write

func (w *WriteCounter) Write(p []byte) (int, error)

Write increments the total byte count.

type ZipContentReader

type ZipContentReader struct {
	Filename string
	// contains filtered or unexported fields
}

ZipContentReader returns the concatenated content of all files in a zip archive given by its filename. All content is temporarily stored in memory, so this type should only be used with smaller archives.

func (*ZipContentReader) Read

func (r *ZipContentReader) Read(p []byte) (int, error)

Read returns the content of all archive members.

type ZipOrPlainLinkReader

type ZipOrPlainLinkReader struct {
	Link string
	// contains filtered or unexported fields
}

ZipOrPlainLinkReader is a reader that transparently handles zipped and uncompressed content, given a URL as string.

func (*ZipOrPlainLinkReader) Read

func (r *ZipOrPlainLinkReader) Read(p []byte) (int, error)

Read implements the reader interface.

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL