gc

package module
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2023 License: BSD-3-Clause Imports: 13 Imported by: 0

README

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

gc

A library for reading and writing Nintendo GameCube memory card images.

Documentation

Index

Examples

Constants

View Source
const (
	MemoryCard59 uint16 = 4 << iota
	MemoryCard123
	MemoryCard251
	MemoryCard507
	MemoryCard1019
	MemoryCard2043
)

Supported memory card sizes.

View Source
const (
	EncodingANSI uint16 = iota
	EncodingSJIS
)

Supported memory card encodings.

Variables

This section is empty.

Functions

func CardSize added in v0.0.6

func CardSize(cardSize uint16) func(*Writer) error

CardSize sets the memory card capacity.

func DetectMemoryCard

func DetectMemoryCard(r io.ReaderAt, size int64) (bool, error)

DetectMemoryCard works out if the io.ReaderAt r pointing to the data of size bytes looks sufficiently like a GameCube memory card image.

func Encoding added in v0.0.6

func Encoding(encoding uint16) func(*Writer) error

Encoding sets the memory card encoding.

func FlashID added in v0.0.6

func FlashID(flashID [12]byte) func(*Writer) error

FlashID sets the 12 byte Flash ID. If the target is an official memory card then this must be set correctly.

func FormatTime added in v0.0.6

func FormatTime(formatTime uint64) func(*Writer) error

FormatTime overrides the formatting time, which is expressed in seconds since 00:00:00, 1st January 2000. Setting it to 0 stops the serial number from being computed.

Types

type File

type File struct {
	FileHeader
	GameCode  string
	MakerCode string
	// contains filtered or unexported fields
}

A File is a single file within a memory card.

func (*File) Open

func (f *File) Open() (fs.File, error)

Open returns an fs.File that provides access to the File's contents. The file is prefixed with a 64 byte header (the directory entry) followed by one or more 8 KiB blocks. Multiple files may be read concurrently.

type FileHeader

type FileHeader struct {
	Name     string
	Modified time.Time
	Size     int64
}

FileHeader describes a file within a memory card.

func (*FileHeader) FileInfo

func (h *FileHeader) FileInfo() fs.FileInfo

FileInfo returns an fs.FileInfo for the FileHeader.

func (*FileHeader) Mode

func (h *FileHeader) Mode() fs.FileMode

Mode returns the permission and mode bits for the FileHeader.

type ReadCloser

type ReadCloser struct {
	Reader
	// contains filtered or unexported fields
}

A ReadCloser is a Reader that must be closed when no longer needed.

func OpenReader

func OpenReader(name string) (*ReadCloser, error)

OpenReader will open the memory card image specified by name and return a ReadCloser.

func (*ReadCloser) Close

func (rc *ReadCloser) Close() error

Close closes the memory card image, rendering it unusable for I/O.

type Reader

type Reader struct {
	File []*File

	FlashID  [12]byte
	CardSize uint16
	Encoding uint16
	// contains filtered or unexported fields
}

A Reader serves content from a memory card image.

func NewReader

func NewReader(r io.Reader) (*Reader, error)

NewReader returns a new Reader reading from r.

func (*Reader) Open

func (r *Reader) Open(name string) (fs.File, error)

Open opens the named file in the memory card image, using the semantics of fs.FS.Open: paths are always slash separated, with no leading / or ../ elements.

type Writer

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

A Writer is used for creating a new memory card image with files written to it.

Example
package main

import (
	"bytes"
	"fmt"

	"github.com/bodgit/gc"
)

func main() {
	buf := new(bytes.Buffer)

	w, err := gc.NewWriter(buf)
	if err != nil {
		panic(err)
	}

	if err := w.Close(); err != nil {
		panic(err)
	}

	fmt.Println(buf.Len())
}
Output:

524288

func NewWriter

func NewWriter(w io.Writer, options ...func(*Writer) error) (*Writer, error)

NewWriter returns a Writer targeting a new blank memory card which defaults to 59 block capacity, ANSI encoding and an all-zeroes Flash ID.

func (*Writer) Close

func (w *Writer) Close() error

Close writes out the memory card to the underlying io.Writer. Any in-flight open memory card files are closed first.

func (*Writer) Create

func (w *Writer) Create() (io.WriteCloser, error)

Create returns an io.WriteCloser for writing a new file on the memory card. The file should consist of a 64 byte header followed by one or more 8 KiB blocks as indicated in the header.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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