gc

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2022 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 collection of libraries and utilities for dealing with Nintendo GameCube file formats.

Full installation:

go get github.com/bodgit/gc/...

Documentation

Index

Examples

Constants

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

Supported memory card sizes.

View Source
const (
	EncodingANSI = iota
	EncodingSJIS
)

Supported memory card encodings.

Variables

This section is empty.

Functions

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.

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

	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, gc.MemoryCard59, gc.EncodingANSI)
	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, capacity, encoding uint16) (*Writer, error)

NewWriter returns a Writer targeting a new blank memory card with the provided capacity and encoding.

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