dcfile

package
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DCFile

type DCFile interface {
	//  ResetTempDirs cleans up or deletes temporary directories.
	ResetTempDirs() error

	//	SetFilePath sets the path to the DwCA file.
	SetFilePath(string)

	//  Extract extracts the content of the DwCA file to a temporary directory.
	Extract() error

	// ArchiveDir returns the path to the temporary directory
	// where DwCA data is located.
	ArchiveDir(path string) (string, error)

	// CoreData returns the content of the core file as a slice of slices of
	// strings. Each slice of strings represents a row in the core file.
	CoreData(root string, meta *meta.Meta, offset, limit int) ([][]string, error)

	// CoreStream populates a channel that streams the content of the core file
	// as a slice of strings. Each slice of strings represents a row in the core
	// file.
	CoreStream(
		ctx context.Context,
		root string,
		meta *meta.Meta,
		coreChan chan<- []string,
	) (int, error)

	// ExtensionData returns the content of the extension file as a slice of
	// slices of strings. Each slice of strings represents a row in the extension
	// file. The index is the index of the extension file in the meta file.
	// The offset and limit are used to paginate the results.
	ExtensionData(
		index int, root string,
		meta *meta.Meta,
		offset, limit int,
	) ([][]string, error)

	// ExtensionStream populates a channel that streams the content of the
	// extension file as a slice of strings. Each slice of strings represents a
	// row in the extension file. The index is the index of the extension file in
	// the meta file.
	ExtensionStream(
		ctx context.Context,
		index int, root string,
		meta *meta.Meta,
		extChan chan<- []string,
	) (int, error)

	// ExportCSVStream saves the content of a stream to a file. The file is a
	// comma-separated file with the first row being the header. The header is
	// defined by the fields parameter. This function is used to export Core or
	// Extension data to a file.
	ExportCSVStream(
		ctx context.Context,
		file string,
		headers []string,
		delim string,
		outChan <-chan []string) error

	// SaveToFile saves bytes slice to a file with the provided name.
	SaveToFile(fileName string, bs []byte) error

	// Zip compresses the content of the temporary output directory to a
	// ZIP file with the provided filePath.
	Zip(inputDir, zipFile string) error

	// TarGz compresses the content of the temporary output directory to a
	// TAR file with the provided filePath.
	TarGz(inputDir, tarFile string) error

	// Close removes the temporary directory with the extracted content.
	Close() error
}

DCFile represents a Darwin Core Archive file. It is normally a compressed tar file or zip file with a set of files inside that correspond to DwCA structure and format.

type ErrContext

type ErrContext struct {
	Err error
}

ErrContext is returned when the context is canceled.

func (*ErrContext) Error

func (e *ErrContext) Error() string

type ErrCoreRead

type ErrCoreRead struct {
	Err error
}

ErrCoreRead is returned when reading the core file fails.

func (*ErrCoreRead) Error

func (e *ErrCoreRead) Error() string

type ErrDir

type ErrDir struct {
	DirPath string
}

ErrDir is returned when the directory is in an unknown state, or is not a directory.

func (*ErrDir) Error

func (e *ErrDir) Error() string

type ErrExtensionRead

type ErrExtensionRead struct {
	Err error
}

func (*ErrExtensionRead) Error

func (e *ErrExtensionRead) Error() string

ErrExtensionRead is returned when reading the extension file fails.

type ErrExtract

type ErrExtract struct {
	Path string
	Err  error
}

ErrExtract is returned when the extraction of the DwCA file fails.

func (*ErrExtract) Error

func (e *ErrExtract) Error() string

type ErrFileNotFound

type ErrFileNotFound struct {
	Path string
}

ErrFileNotFound is returned when the file is not found.

func (*ErrFileNotFound) Error

func (e *ErrFileNotFound) Error() string

type ErrMetaFileNotFound

type ErrMetaFileNotFound struct{}

ErrMetaFileNotFound is returned when the meta.xml file is not found in the extract directory.

func (*ErrMetaFileNotFound) Error

func (e *ErrMetaFileNotFound) Error() string

type ErrMultipleMetaFiles

type ErrMultipleMetaFiles struct{}

ErrMultipleMetaFiles is returned when there are multiple meta.xml files in the extract directory.

func (*ErrMultipleMetaFiles) Error

func (e *ErrMultipleMetaFiles) Error() string

type ErrSaveCSV

type ErrSaveCSV struct {
	Err error
}

func (*ErrSaveCSV) Error

func (e *ErrSaveCSV) Error() string

type ErrUnknownArchiveType

type ErrUnknownArchiveType struct {
	FileType
}

ErrUnknownArchiveType is returned when the file type is not supported.

func (*ErrUnknownArchiveType) Error

func (e *ErrUnknownArchiveType) Error() string

type FileType

type FileType int
const (
	Unknown FileType = iota
	ZIP              // .zip
	TAR              // .tar
	TARGZ            // .tar.gz
	TARXZ            // .tar.xz
	TARBZ2           //.tar.bz2
)

func NewFileType

func NewFileType(file string) FileType

func (FileType) String

func (ft FileType) String() string

Jump to

Keyboard shortcuts

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