rom

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2023 License: BSD-3-Clause Imports: 16 Imported by: 1

README

GitHub release Build Status Coverage Status Go Report Card GoDoc Go version Go version

rom

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrNotTorrentZip is returned if a zip file does not have the
	// correct archive comment
	ErrNotTorrentZip = errors.New("not a torrent zip")
)

Functions

This section is empty.

Types

type Checksum

type Checksum int

Checksum is used to specify a checksum/hash type

const (
	CRC32 Checksum = iota
	MD5
	SHA1
)

Supported checksum/hash types

type DirectoryReader

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

DirectoryReader reads a directory and provides access to any regular files contained within. Hidden files, directories and any files not in the immediate directory are inaccessible

func NewDirectoryReader

func NewDirectoryReader(directory string) (*DirectoryReader, error)

NewDirectoryReader returns a new DirectoryReader for the passed directory

func (*DirectoryReader) Checksum

func (r *DirectoryReader) Checksum(filename string, checksum Checksum) ([]byte, error)

Checksum computes the checksum for the passed file

func (*DirectoryReader) Close

func (r *DirectoryReader) Close() error

Close closes access to the underlying file. Any other methods are not guaranteed to work after this has been called

func (*DirectoryReader) Files

func (r *DirectoryReader) Files() []string

Files returns all files accessible by the implementation.

func (*DirectoryReader) Name

func (r *DirectoryReader) Name() string

Name returns the full path to the underlying file

func (*DirectoryReader) Open

func (r *DirectoryReader) Open(filename string) (io.ReadCloser, error)

Open returns an io.ReadCloser for any file listed by the Files method

func (*DirectoryReader) Rx

func (r *DirectoryReader) Rx() uint64

Rx returns the number of bytes read by the implementation

func (*DirectoryReader) Size

func (r *DirectoryReader) Size(filename string) (uint64, uint64, error)

Size returns the size of any file listed by the Files method

type DirectoryWriter

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

DirectoryWriter creates a directory if necessary and then writes new files inside it

func NewDirectoryWriter

func NewDirectoryWriter(directory string) (*DirectoryWriter, error)

NewDirectoryWriter returns a new DirectoryWriter for the passed directory. Any existing files within it are removed

func (*DirectoryWriter) Close

func (w *DirectoryWriter) Close() error

Close closes access to the underlying file. Any other methods are not guaranteed to work after this has been called

func (*DirectoryWriter) Create

func (w *DirectoryWriter) Create(filename string) (io.WriteCloser, error)

Create returns an io.WriteCloser for the requested filename. The ability to create multiple files in parallel rather than sequentially is implementation-dependent

func (*DirectoryWriter) Name

func (w *DirectoryWriter) Name() string

Name returns the full path to the underlying file

func (*DirectoryWriter) Tx

func (w *DirectoryWriter) Tx() uint64

Tx returns the number of bytes written by the implementation

type FileReader

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

FileReader reads a single regular file and coerces it into looking like an archive containing exactly one file

func NewFileReader

func NewFileReader(filename string) (*FileReader, error)

NewFileReader returns a new FileReader for the passed filename

func (*FileReader) Checksum

func (r *FileReader) Checksum(filename string, checksum Checksum) ([]byte, error)

Checksum computes the checksum for the passed file

func (*FileReader) Close

func (r *FileReader) Close() error

Close closes access to the underlying file. Any other methods are not guaranteed to work after this has been called

func (*FileReader) Files

func (r *FileReader) Files() []string

Files returns all files accessible by the implementation.

func (*FileReader) Name

func (r *FileReader) Name() string

Name returns the full path to the underlying file

func (*FileReader) Open

func (r *FileReader) Open(filename string) (io.ReadCloser, error)

Open returns an io.ReadCloser for any file listed by the Files method

func (*FileReader) Rx

func (r *FileReader) Rx() uint64

Rx returns the number of bytes read by the implementation

func (*FileReader) Size

func (r *FileReader) Size(filename string) (uint64, uint64, error)

Size returns the size of any file listed by the Files method

type FileWriter

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

FileWriter writes a single regular file as if it was an archive containing exactly one file. The one file must match the base name of the target

func NewFileWriter

func NewFileWriter(filename string) (*FileWriter, error)

NewFileWriter returns a new FileWriter for the passed filename

func (*FileWriter) Close

func (w *FileWriter) Close() error

Close closes access to the underlying file. Any other methods are not guaranteed to work after this has been called

func (*FileWriter) Create

func (w *FileWriter) Create(filename string) (io.WriteCloser, error)

Create returns an io.WriteCloser for the requested filename. The ability to create multiple files in parallel rather than sequentially is implementation-dependent

func (*FileWriter) Name

func (w *FileWriter) Name() string

Name returns the full path to the underlying file

func (*FileWriter) Tx

func (w *FileWriter) Tx() uint64

Tx returns the number of bytes written by the implementation

type RarReader

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

RarReader reads a RAR archive and provides access to any regular files contained within. Hidden files, directories and any files not in the top level are inaccessible. Password-protected archives are not supported

func NewRarReader

func NewRarReader(filename string) (r *RarReader, err error)

NewRarReader returns a new RarReader for the passed filename

func (*RarReader) Checksum

func (r *RarReader) Checksum(filename string, checksum Checksum) ([]byte, error)

Checksum computes the checksum for the passed file, it will not include any header that might be present

func (*RarReader) Close

func (r *RarReader) Close() error

Close closes access to the underlying file. Any other methods are not guaranteed to work after this has been called

func (*RarReader) Files

func (r *RarReader) Files() []string

Files returns all files accessible by the implementation.

func (*RarReader) Name

func (r *RarReader) Name() string

Name returns the full path to the underlying file

func (*RarReader) Open

func (r *RarReader) Open(filename string) (rc io.ReadCloser, err error)

Open returns an io.ReadCloser for any file listed by the Files method

func (*RarReader) Rx

func (r *RarReader) Rx() uint64

Rx returns the number of bytes read by the implementation

func (*RarReader) Size

func (r *RarReader) Size(filename string) (uint64, uint64, error)

Size returns the size of any file listed by the Files method and the size of any header that is present

type Reader

type Reader interface {
	// Checksum computes the checksum for the passed file, it will not include any header that might be present
	Checksum(string, Checksum) ([]byte, error)
	// Close closes access to the underlying file. Any other methods
	// are not guaranteed to work after this has been called
	Close() error
	// Files returns all files accessible by the implementation.
	Files() []string
	// Name returns the full path to the underlying file
	Name() string
	// Open returns an io.ReadCloser for any file listed by the Files
	// method
	Open(string) (io.ReadCloser, error)
	// Rx returns the number of bytes read by the implementation
	Rx() uint64
	// Size returns the size of any file listed by the Files method and the size of any header that is present
	Size(string) (uint64, uint64, error)
}

Reader is the interface implemented by all ROM readers

func NewReader

func NewReader(path string) (Reader, error)

NewReader uses heuristics to work out the type of file passed and uses the most appropriate Reader to access it

type SevenZipReader

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

SevenZipReader reads a 7zip archive and provides access to any regular files contained within. Hidden files, directories and any files not in the top level are inaccessible

func NewSevenZipReader

func NewSevenZipReader(filename string) (r *SevenZipReader, err error)

NewSevenZipReader returns a new SevenZipReader for the passed 7zip archive

func (*SevenZipReader) Checksum

func (r *SevenZipReader) Checksum(filename string, checksum Checksum) ([]byte, error)

Checksum computes the checksum for the passed file. CRC values for files that don't have special requirements use the value from the central directory

func (*SevenZipReader) Close

func (r *SevenZipReader) Close() error

Close closes access to the underlying file. Any other methods are not guaranteed to work after this has been called

func (*SevenZipReader) Files

func (r *SevenZipReader) Files() []string

Files returns all files accessible by the implementation.

func (*SevenZipReader) Name

func (r *SevenZipReader) Name() string

Name returns the full path to the underlying file

func (*SevenZipReader) Open

func (r *SevenZipReader) Open(filename string) (io.ReadCloser, error)

Open returns an io.ReadCloser for any file listed by the Files method

func (*SevenZipReader) Rx

func (r *SevenZipReader) Rx() uint64

Rx returns the number of bytes read by the implementation

func (*SevenZipReader) Size

func (r *SevenZipReader) Size(filename string) (uint64, uint64, error)

Size returns the size of any file listed by the Files method

type TorrentZipReader

type TorrentZipReader struct {
	*ZipReader
	// contains filtered or unexported fields
}

TorrentZipReader reads a zip archive and provides access to any regular files contained within. Hidden files, directories and any files not in the top level are inaccessible

func NewTorrentZipReader

func NewTorrentZipReader(filename string) (r *TorrentZipReader, err error)

NewTorrentZipReader returns a new TorrentZipReader for the passed zip archive. It extends NewZipReader to check that the zip archive has the correctly formatted comment and validates that the CRC of the central directory matches the comment value

func (*TorrentZipReader) Valid

func (r *TorrentZipReader) Valid() bool

Valid confirms the checksum of the central directory in the zip archive matches the value in the archive comment

type TorrentZipWriter

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

TorrentZipWriter creates a new zip archive using the torrentzip standard. It is slightly slower to create than a normal zip archive

func NewTorrentZipWriter

func NewTorrentZipWriter(filename string) (*TorrentZipWriter, error)

NewTorrentZipWriter returns a new TorrentZipWriter for the passed zip archive

func (*TorrentZipWriter) Close

func (w *TorrentZipWriter) Close() error

Close closes access to the underlying file. Any other methods are not guaranteed to work after this has been called

func (*TorrentZipWriter) Create

func (w *TorrentZipWriter) Create(filename string) (io.WriteCloser, error)

Create returns an io.WriteCloser for the requested filename. The ability to create multiple files in parallel rather than sequentially is implementation-dependent

func (*TorrentZipWriter) Name

func (w *TorrentZipWriter) Name() string

Name returns the full path to the underlying file

func (*TorrentZipWriter) Tx

func (w *TorrentZipWriter) Tx() uint64

Tx returns the number of bytes written by the implementation

type Validator

type Validator interface {
	// Valid returns if the underlying file or container is considered
	// correct
	Valid() bool
}

Validator is the interface optionally implemented by a ROM reader if it can validate its integrity somehow

type Writer

type Writer interface {
	// Close closes access to the underlying file. Any other methods
	// are not guaranteed to work after this has been called
	Close() error
	// Create returns an io.WriteCloser for the requested filename. The
	// ability to create multiple files in parallel rather than
	// sequentially is implementation-dependent
	Create(string) (io.WriteCloser, error)
	// Name returns the full path to the underlying file
	Name() string
	// Tx returns the number of bytes written by the implementation
	Tx() uint64
}

Writer is the interface implemented by all ROM writers

type ZipReader

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

ZipReader reads a zip archive and provides access to any regular files contained within. Hidden files, directories and any files not in the top level are inaccessible

func NewZipReader

func NewZipReader(filename string) (r *ZipReader, err error)

NewZipReader returns a new ZipReader for the passed zip archive

func (*ZipReader) Checksum

func (r *ZipReader) Checksum(filename string, checksum Checksum) ([]byte, error)

Checksum computes the checksum for the passed file. CRC values for files that don't have special requirements use the value from the central directory

func (*ZipReader) Close

func (r *ZipReader) Close() error

Close closes access to the underlying file. Any other methods are not guaranteed to work after this has been called

func (*ZipReader) Files

func (r *ZipReader) Files() []string

Files returns all files accessible by the implementation.

func (*ZipReader) Name

func (r *ZipReader) Name() string

Name returns the full path to the underlying file

func (*ZipReader) Open

func (r *ZipReader) Open(filename string) (io.ReadCloser, error)

Open returns an io.ReadCloser for any file listed by the Files method

func (*ZipReader) Rx

func (r *ZipReader) Rx() uint64

Rx returns the number of bytes read by the implementation

func (*ZipReader) Size

func (r *ZipReader) Size(filename string) (uint64, uint64, error)

Size returns the size of any file listed by the Files method

type ZipWriter

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

ZipWriter creates a new zip archive

func NewZipWriter

func NewZipWriter(filename string) (*ZipWriter, error)

NewZipWriter returns a new ZipWriter for the passed zip archive

func (*ZipWriter) Close

func (w *ZipWriter) Close() error

Close closes access to the underlying file. Any other methods are not guaranteed to work after this has been called

func (*ZipWriter) Create

func (w *ZipWriter) Create(filename string) (io.WriteCloser, error)

Create returns an io.WriteCloser for the requested filename. The ability to create multiple files in parallel rather than sequentially is implementation-dependent

func (*ZipWriter) Name

func (w *ZipWriter) Name() string

Name returns the full path to the underlying file

func (*ZipWriter) Tx

func (w *ZipWriter) Tx() uint64

Tx returns the number of bytes written by the implementation

Notes

Bugs

  • RarReader is not very I/O efficient due to the underlying implementation

  • The bytes written for TorrentZipWriter is not accurate

Directories

Path Synopsis
cmd
rom
Package dat implements parsing of XML dat files as commonly used by ROM/Disc preservation projects such as http://redump.org and https://no-intro.org.
Package dat implements parsing of XML dat files as commonly used by ROM/Disc preservation projects such as http://redump.org and https://no-intro.org.
Package synchronizer implements a set of methods to maintain a pristine directory of TorrentZip files representing the games in a dat file.
Package synchronizer implements a set of methods to maintain a pristine directory of TorrentZip files representing the games in a dat file.

Jump to

Keyboard shortcuts

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