ar

package module
v0.0.0-...-c0901a8 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2022 License: ISC Imports: 7 Imported by: 0

README

AR archive format

Introduction

This library provides readers and writers with GNU ar archive files.

Documentation

You can use the standard Go documentation tool to read code documentation, for example:

go doc -all github.com/gearnode/ar

Contact

If you find a bug or have any question, feel free to open a Github issue or to contact me by email.

Please note that I do not currently review or accept any contribution.

Licence

Released under the ISC license.

Copyright (c) 2022 Bryan Frimin bryan@frimin.fr.

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

Documentation

Index

Constants

View Source
const (
	HeaderByteSize = 60
	MagicString    = "!<arch>\n"
)

Variables

View Source
var (
	ErrWriteTooLong = errors.New("write too long")
)

Functions

This section is empty.

Types

type Header struct {
	// File identifier
	Name string

	// File modification timestamp
	Date time.Time

	// Owner ID
	Uid int64

	// Group ID
	Gid int64

	// File mode (type and permission)
	Mode int64

	// File size in bytes
	Size int64
}

type Reader

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

Reader provides sequential access to the contents of a ar archive.

Reader.Next advances to the next file in the archive (including the first), and then Reader can be treated as an io.Reader to access the file's data.

func NewReader

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

NewReader creates a new Reader reading from r.

An error is returned when the reader is not an ar file.

func (*Reader) Next

func (r *Reader) Next() (*Header, error)

Next advances to the next entry in the ar archive.

The Header.Size determines how many bytes can be read for the next file. Any remaining data in the current file is automatically discarded.

io.EOF is returned at the end of the input.

func (*Reader) Read

func (r *Reader) Read(b []byte) (int, error)

Read reads from the current file in the ar archive.

It returns (0, io.EOF) when it reaches the end of that file, until Next is called to advance to the next file.

type Writer

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

Writer provides sequential writing of a ar archive.

Write.WriteMagicBytes begins a new file, then WriteHeader begins a new file with the provided Header, and then Writer can be treated as an io.Writer to supply that file's data.

func NewWriter

func NewWriter(w io.Writer) *Writer

NewWriter creates a new Writer writing to w.

func (*Writer) Write

func (w *Writer) Write(b []byte) (int, error)

Write writes to the current file in the ar archive.

Write returns the error ErrWriteTooLong if more than Header.Size bytes are written after WriteHeader.

func (*Writer) WriteHeader

func (w *Writer) WriteHeader(header *Header) error

WriteHeader writes header and prepares to accept the file's contents.

The Header.Size determines how many bytes can be written for the next file. If the current file is not fully written, then this returns an error.

func (*Writer) WriteMagicBytes

func (w *Writer) WriteMagicBytes() error

WriteMagicBytes writes ar magic bytes header.

Jump to

Keyboard shortcuts

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