mrk

package
v0.33.0 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package mrk reads and writes MARC 21 records in the MARCMaker / MARCBreaker mnemonic line format (".mrk"), implementing codex.RecordReader and codex.RecordWriter using only the standard library.

Each field is one line beginning with "=": "=LDR " carries the leader, and "=TAG " carries a field, where TAG is the 3-character tag followed by two spaces. A control field (tag below "010") is the raw value; a data field is two indicator characters — a blank indicator written as a backslash ("\") — followed by subfields, each introduced by "$" and a one-character code. Records are separated by a blank line:

=LDR  00000nam a2200000   4500
=001  ocm12345
=245  10$aStone butch blues :$ba novel /$cLeslie Feinberg.
=650  \0$aLesbians

The literal characters "$", "{", "}" and "&" are written as the mnemonics {dollar}, {lcub}, {rcub} and {amp}; decoding also accepts numeric character references (&#xHHHH; and &#DDDD;). Values are otherwise UTF-8; the wider MARC-8 mnemonic repertoire is out of scope.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(b []byte) (*codex.Record, error)

Decode parses a single record from a .mrk byte slice.

func Encode

func Encode(r *codex.Record) ([]byte, error)

Encode serializes a record to its .mrk lines (no trailing record separator).

func ReadFile

func ReadFile(path string) ([]*codex.Record, error)

ReadFile reads every record from the named .mrk file. On the first malformed record it returns the records parsed so far together with the error.

func WriteFile

func WriteFile(path string, records []*codex.Record) error

WriteFile writes every record to the named file, creating it or truncating an existing file.

Types

type Reader

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

Reader reads MARC records from a .mrk stream one record at a time.

func NewReader

func NewReader(r io.Reader) *Reader

NewReader returns a Reader that reads records from r.

func (*Reader) All

func (rd *Reader) All() iter.Seq2[*codex.Record, error]

All returns an iterator over the remaining records, for use as "for rec, err := range r.All()". It stops at the first error.

func (*Reader) Read

func (rd *Reader) Read() (*codex.Record, error)

Read returns the next record, or io.EOF when the stream is exhausted. A record is the run of "=" lines up to the next blank line or end of input.

type Writer

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

Writer writes records to a .mrk stream, separating them with a blank line.

func NewWriter

func NewWriter(w io.Writer) *Writer

NewWriter returns a Writer that writes records to w.

func (*Writer) Close added in v0.6.0

func (wr *Writer) Close() error

Close reports the first write error, if any, and rejects further writes. The mrk stream needs no trailer, so Close flushes nothing; it exists for parity with the marcxml and marcjson writers.

func (*Writer) Write

func (wr *Writer) Write(r *codex.Record) error

Write serializes one record and writes it, followed by a blank line. After a write error the Writer is sticky: every later call returns the same error.

Jump to

Keyboard shortcuts

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