collection

package
v1.9.14 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: MIT Imports: 16 Imported by: 0

README

Коллекция файлов.

Пакет предоставляет реализацию интерфейса github.com/D3rus/go-library/file/Collection которая находится в файле files.go.

Так же пакет предоставляет несколько оберток:

  • TarGZ - если файлы находятся в архивах tar.gz, при вызове метода Next архив будет распакован, метод конструктор NewTarGZ(collection file.Collection, directory string), directory - путь до директории, в которую будут распаковываться архивы;
  • ZIP - если файлы находятся в архивах zip, при вызове метода Next архив будет распакован, метод конструктор NewZIP(collection file.Collection, directory string), directory - путь до директории, в которую будут распаковываться архивы;
  • Context - отслеживает закрытие контекста, если контекст закрыт, при вызове метода Next вернет ошибку io.EOF, вне зависимости от кол. оставшихся файлов, метод конструктор NewContext(collection file.Collection, ctx context.Context).

Обертки реализованы для использования их с интерфейсом github.com/D3rus/go-library/file/Collection, что позволяет использовать их отдельно.

Пакет предоставляет метод New(directory string, namer file.Namer, options ...file.CollectionOption) (file.Collection, error), для легкого получения готового объекта коллекции файлов, directory - путь до директории в которой расположены файлы, options - является опциональным аргументом, пакет предоставляет следующие методы опций:

  • WithArchiveTarGZ - добавляет обертку TarGZ;
  • WithArchiveZIP - добавляет обертку ZIP;
  • WithArchive - добавляет обертку TarGZ либо ZIP, выбор обертки проходит автоматически в зависимости от ОС, для всех UNIX подобных систем будет выбран тип архивов TarGZ, для Windows ZIP;
  • WithContext - добавляет обертку Context;
  • WithCheckDirectory - проверяет директорию на существование и доступность, если директория не существует, создает её;
  • WithFileCount - устанавливает в метрике кол. файлов, на момент создания коллекции.

Важно. Все опции будут примениться в той последовательности, в которой они были переданы.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(directory string, namer file.Namer, options ...file.CollectionOption) (file.Collection, error)

func WithArchive

func WithArchive(directory string) file.CollectionOption

func WithArchiveTarGZ

func WithArchiveTarGZ(directory string) file.CollectionOption

func WithArchiveZIP

func WithArchiveZIP(directory string) file.CollectionOption

func WithCheckDirectory

func WithCheckDirectory(directoryPath string) file.CollectionOption

func WithContext

func WithContext(ctx context.Context) file.CollectionOption

func WithFileCount

func WithFileCount(counter prometheus.Gauge, directory string) file.CollectionOption

Types

type Context

type Context struct {
	file.Collection
	// contains filtered or unexported fields
}

func NewContext

func NewContext(collection file.Collection, ctx context.Context) *Context

func (*Context) Next

func (collection *Context) Next() (*os.File, error)

type Files

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

func NewFiles

func NewFiles(directory string, namer file.Namer) *Files

func (*Files) Count

func (collection *Files) Count() int

func (*Files) Namer

func (collection *Files) Namer() file.Namer

func (*Files) Next

func (collection *Files) Next() (*os.File, error)

type TarGZ

type TarGZ struct {
	file.Collection
	// contains filtered or unexported fields
}

func NewTarGZ

func NewTarGZ(collection file.Collection, directory string) *TarGZ

func (*TarGZ) Next

func (archive *TarGZ) Next() (*os.File, error)

type ZIP

type ZIP struct {
	file.Collection
	// contains filtered or unexported fields
}

func NewZIP

func NewZIP(collection file.Collection, directory string) *ZIP

func (*ZIP) Next

func (archive *ZIP) Next() (*os.File, error)

Jump to

Keyboard shortcuts

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