ar

package module
v0.0.0-...-809d437 Latest Latest
Warning

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

Go to latest
Published: May 2, 2019 License: MIT Imports: 6 Imported by: 63

README

Golang ar (archive) file reader

This is a simple library for reading and writing ar files in common format. It is influenced heavily in style and interface from the golang tar package.

Author

Written by Blake Smith blakesmith0@gmail.com

Licensed under the MIT license.

Documentation

Overview

Copyright (c) 2013 Blake Smith <blakesmith0@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Copyright (c) 2013 Blake Smith <blakesmith0@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Copyright (c) 2013 Blake Smith <blakesmith0@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Index

Constants

View Source
const (
	HEADER_BYTE_SIZE = 60
	GLOBAL_HEADER    = "!<arch>\n"
)

Variables

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

Functions

This section is empty.

Types

type Header struct {
	Name    string
	ModTime time.Time
	Uid     int
	Gid     int
	Mode    int64
	Size    int64
}

type Reader

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

func NewReader

func NewReader(r io.Reader) *Reader

Copies read data to r. Strips the global ar header.

func (*Reader) Next

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

Call Next() to skip to the next file in the archive file. Returns a Header which contains the metadata about the file in the archive.

func (*Reader) Read

func (rd *Reader) Read(b []byte) (n int, err error)

Read data from the current entry in the archive.

type Writer

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

Writer provides sequential writing of an ar archive. An ar archive is sequence of header file pairs Call WriteHeader to begin writing a new file, then call Write to supply the file's data

Example: archive := ar.NewWriter(writer) archive.WriteGlobalHeader() header := new(ar.Header) header.Size = 15 // bytes

if err := archive.WriteHeader(header); err != nil {
	return err
}

io.Copy(archive, data)

func NewWriter

func NewWriter(w io.Writer) *Writer

Create a new ar writer that writes to w

func (*Writer) Write

func (aw *Writer) Write(b []byte) (n int, err error)

Writes to the current entry in the ar archive Returns ErrWriteTooLong if more than header.Size bytes are written after a call to WriteHeader

func (*Writer) WriteGlobalHeader

func (aw *Writer) WriteGlobalHeader() error

func (*Writer) WriteHeader

func (aw *Writer) WriteHeader(hdr *Header) error

Writes the header to the underlying writer and prepares to receive the file payload

Jump to

Keyboard shortcuts

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