tarindex

package
v0.1.23 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2026 License: AGPL-3.0 Imports: 6 Imported by: 0

README

TAR Index

A TAR index file describes the layout of a TAR archive file. It contains metadata about each file entry in the archive:

  • Header Position: The byte offset where the file's TAR header begins
  • Header Blocks: The number of 512-byte blocks occupied by the TAR header
  • File Size: The total number of bytes in the file content

Binary Format

To minimize file size, the index uses a compact binary format with the following structure:

Field Size Description
Header Position 8 bytes Byte offset to the TAR header
Header Blocks 2 bytes Number of 512-byte blocks for the header
File Size 6 bytes Total file size in bytes

All values are stored in big-endian byte order.

Example

For a file with:

  • Header at byte position 1024
  • Header spanning 1 block (512 bytes)
  • File size of 2048 bytes

The index entry would be: 00 00 00 00 00 00 04 00 00 01 00 00 00 00 08 00

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IndexTar

func IndexTar(r io.Reader) ([]byte, error)

Types

type FileMetadata

type FileMetadata struct {
	Start        int64
	HeaderBlocks uint16
	Size         int64
}

FileMetadata contains the metadata for a file in the index. Start is the offset of the file in the tar archive. HeaderBlocks is the number of blocks in the header of the file (each block is 512 bytes). Size is the size of the file in bytes.

type Index

type Index struct {
	Bytes []byte
	// contains filtered or unexported fields
}

func OpenTarIndex

func OpenTarIndex(name string) (*Index, error)

OpenTarIndex opens a tar index file and returns an Index object. name is the path to the index file. Returns nil and an error if the file cannot be opened.

func (*Index) Close

func (i *Index) Close() error

func (*Index) GetFileMetadata

func (i *Index) GetFileMetadata(index uint64) (FileMetadata, error)

GetFileMetadata returns the metadata for a file in the index. index is the index of the file in the index. Returns the metadata for the file.

func (*Index) NumFiles

func (i *Index) NumFiles() uint64

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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