record

package
v1.11.13 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2024 License: Apache-2.0 Imports: 37 Imported by: 0

Documentation

Overview

Package record creates an object that can be written as JSON or used as a new database record.

Index

Constants

View Source
const (
	FileID   = "file_id.diz"        // FileID is the filename of the release mini-descriptor.
	Section  = "releaseinformation" // Section releaseinformation is the default category tag for NFOs and file_id.diz.
	Platform = "text"               // Platform text is the default file format or NFOs and file_id.diz.
)
View Source
const (
	CreateMode = 0o666
)

Variables

View Source
var (
	ErrDir     = errors.New("the named file points to a directory")
	ErrGroup   = errors.New("record group field cannot be empty")
	ErrNew     = errors.New("new record name and group cannot be empty")
	ErrPointer = errors.New("pointer value cannot be nil")
)
View Source
var ErrFile = errors.New("os file cannot be nil")

Functions

func Copy

func Copy(dst, src string) (written int64, err error)

Copy the src filepath to the dst.

func Determine

func Determine(name string) (string, error)

Determine the magic file definition of the named file.

func Sum386

func Sum386(f *os.File) (string, error)

Sum386 returns the SHA-386 checksum value of the open file.

func SumMD5

func SumMD5(f *os.File) (string, error)

SumMD5 returns the MD5 checksum value of the open file.

func Zip

func Zip(s string) string

Types

type Download

type Download struct {
	Path       string    // Path to the file that is open for reading and checksums.
	Name       string    // Name of the base file.
	Bytes      int64     // Bytes size of the file.
	HashStrong string    // HashStrong is the SHA-386 checksum.
	HashWeak   string    // HashWeak is the MD5 checksum.
	Magic      string    // Magic file type.
	ModTime    time.Time // ModTime is the last modification date of the file.
	ReadTitle  string    // Title of the release, read from a file_id.diz.
	ReadDate   time.Time // Publish date of the release, read from a file_id.diz.
}

Download file metadata, the download is usually either a ZIP archive or a single textfile such as an NFO or file_id.diz.

func (*Download) Create

func (dl *Download) Create(name, group string) error

Create a download from the named file. The group must be the formal release-group name.

func (*Download) ReadDIZ

func (dl *Download) ReadDIZ(body, group string) error

ReadDIZ sets the title and publish date of the download using the body string sourced from a file_id.diz metadata file.

func (*Download) ReadNfo

func (dl *Download) ReadNfo(body, group string) error

ReadNfo sets the publish date of the download using the body string sourced from a group.nfo file. This is a fallback for when ReadDIZ cannot be used.

type Record

type Record struct {
	UUID       string    `json:"uuid"`
	Slug       string    `json:"slug"`
	Title      string    `json:"record_title"`
	Group      string    `json:"group_brand_for"`
	FileName   string    `json:"filename"`
	FileSize   int64     `json:"filesize"`
	FileMagic  string    `json:"file_magic_type"`
	HashStrong string    `json:"file_integrity_strong"`
	HashWeak   string    `json:"file_integrity_weak"`
	LastMod    time.Time `json:"file_last_modified"`
	ZipContent string    `json:"file_zip_content"`
	Published  time.Time `json:"date_issued"`
	Section    string    `json:"section"`
	Platform   string    `json:"platform"`
	Comment    string    `json:"comment"`
	Readme     string    `json:"retrotxt_readme"`
	TempPath   string    `json:"temp_path"` // TempPath to the temporary UUID named file download.
}

Record contains the fields that will be used as database cell values.

func New

func New(uid, name, group string) (Record, error)

New creates a Record. The uid must be a valid UUID or returns an error. The name must be the subdirectory of the release. The group must be the formal release-group name.

func (Record) Insert

func (rec Record) Insert(ctx context.Context, db *sql.DB, newpath string) error

type Records

type Records []Record

Records are a collection of Record items to insert into the database.

func (Records) Insert

func (imports Records) Insert(
	ctx context.Context, db *sql.DB, l *zap.SugaredLogger, path string, limit uint,
) (int, error)

Jump to

Keyboard shortcuts

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