readme

package
v1.14.5 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: GPL-3.0 Imports: 22 Imported by: 0

Documentation

Overview

Package readme provides functions for reading and suggesting readme files.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDownload = errors.New("readme: cannot stat the downloaded file")
	ErrFilename = errors.New("readme: file model filename is empty")
	ErrUUID     = errors.New("readme: file model uuid is empty")
	ErrTooLong  = errors.New("readme: reader is larger than 1MB")
)

Functions

func AddPrefix added in v1.14.0

func AddPrefix(p, prefix []byte) []byte

AddPrefix injects content before the existing byte content. This is usually to inject FILE_ID.DIZ text files.

func AddSuffix added in v1.14.0

func AddSuffix(p, suffix []byte) []byte

AddSuffix injects content after the existing byte content. This is usually to inject an additional helper text file.

func Normalize added in v1.14.0

func Normalize(b []byte) []byte

Normalize applies a number of replacements and sanity checks to the byte slice to make it ready for use to display on a user's browser.

  • EOF marker is removed
  • ASCII NULLs are swapped with spaces
  • CFLF newlines are swapped with LF newlines
  • Keywords are masked
  • SAUCE metadata and comments are removed
  • E-grave end of file marker is removed

func SortList added in v1.9.11

func SortList(compact bool, entries string) []string

SortList returns a sorted list of possible readme text files found in the file archive. The first result is the closes filename to root that has a priority filename extension such as ".nfo", then ordered alphabetically.

When compact is true all filenames using extensions that are not known textfiles, are removed from the slice.

To save memory, content is not split into a slice until we need to handle it.

func Suggest

func Suggest(name, group, entries string) string

Suggest returns a suggested readme file name for the record. It prioritizes the filename and group name with a priority extension, such as ".nfo", ".txt", etc. If no priority extension is found, it will return the first text file in the content list.

  • The name string should be the original filename of the archive.
  • The group should be a known name or common abbreviation,
  • The content should be a list of the archive entries.

Types

type Text added in v1.14.0

type Text struct {
	Download dir.Directory
	Extra    dir.Directory
	UUID     string
	Filename string
	Platform string
	Section  string
	Year     int16
	MaxSize  int64
	Sign     magicnumber.Signature
	Record   sauce.Record
}

func (*Text) Buffers added in v1.14.0

func (t *Text) Buffers(sl *slog.Logger) (*bytes.Buffer, *bytes.Buffer, error)

Buffers parses the text files assigned to an artifact. There is a possibility of up to three source files: uuid_filename.diz, uuid_filename.txt, uuid_filename.hlp.

Comparing 8-bit IBM Codepage encodings against UTF-8 is unreliable, so after parsing, two buffers are returned:

  • buffer 1 contains CP-1252 and ISO-8859-1 friendly text
  • buffer 2 contains UTF-8 text using multi-byte characters

Buffer 2 is left empty whenever ANSI encoded or MSDOS binary texts are handled.

If there are no source text files found, or if the found data of the source files is unusable, then the returned buffers will be empty.

Errors are generally logged instead of returned, except with some critical issues. This is to allow the continued rendering of text, say if the ".diz" handler causes an error, Text.Buffers can continue to parse and return the ".txt" and ".hlp" texts.

func (*Text) Error added in v1.14.0

func (t *Text) Error(sl *slog.Logger, err error)

Error logs the error as a warning with useful Text metadata.

Jump to

Keyboard shortcuts

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