Show / Hide Table of Contents

Class TarHeader

This class encapsulates the Tar Entry Header used in Tar Archives. The class also holds a number of tar constants, used mostly in headers.

Inheritance
System.Object
TarHeader
Inherited Members
System.Object.Equals(System.Object, System.Object)
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: ICSharpCode.SharpZipLib.Tar
Assembly: ICSharpCode.SharpZipLib.dll
Syntax
public class TarHeader
Remarks

The tar format and its POSIX successor PAX have a long history which makes for compatability issues when creating and reading files.

This is further complicated by a large number of programs with variations on formats One common issue is the handling of names longer than 100 characters. GNU style long names are currently supported.

This is the ustar (Posix 1003.1) header.

struct header { char t_name[100]; // 0 Filename char t_mode[8]; // 100 Permissions char t_uid[8]; // 108 Numerical User ID char t_gid[8]; // 116 Numerical Group ID char t_size[12]; // 124 Filesize char t_mtime[12]; // 136 st_mtime char t_chksum[8]; // 148 Checksum char t_typeflag; // 156 Type of File char t_linkname[100]; // 157 Target of Links char t_magic[6]; // 257 "ustar" or other... char t_version[2]; // 263 Version fixed to 00 char t_uname[32]; // 265 User Name char t_gname[32]; // 297 Group Name char t_devmajor[8]; // 329 Major for devices char t_devminor[8]; // 337 Minor for devices char t_prefix[155]; // 345 Prefix for t_name char t_mfill[12]; // 500 Filler up to 512 };

Constructors

| Improve this Doc View Source

TarHeader()

Initialise a default TarHeader instance

Declaration
public TarHeader()

Fields

| Improve this Doc View Source

CHKSUMLEN

The length of the checksum field in a header buffer.

Declaration
public const int CHKSUMLEN = 8
Field Value
Type Description
System.Int32
| Improve this Doc View Source

CHKSUMOFS

Offset of checksum in a header buffer.

Declaration
public const int CHKSUMOFS = 148
Field Value
Type Description
System.Int32
| Improve this Doc View Source

DEVLEN

The length of the devices field in a header buffer.

Declaration
public const int DEVLEN = 8
Field Value
Type Description
System.Int32
| Improve this Doc View Source

GIDLEN

The length of the group id field in a header buffer.

Declaration
public const int GIDLEN = 8
Field Value
Type Description
System.Int32
| Improve this Doc View Source

GNAMELEN

The length of the group name field in a header buffer.

Declaration
public const int GNAMELEN = 32
Field Value
Type Description
System.Int32
| Improve this Doc View Source

GNU_TMAGIC

The magic tag representing an old GNU tar archive where version is included in magic and overwrites it

Declaration
public const string GNU_TMAGIC = "ustar  "
Field Value
Type Description
System.String
| Improve this Doc View Source

LF_ACL

Solaris access control list file type

Declaration
public const byte LF_ACL = 65
Field Value
Type Description
System.Byte
| Improve this Doc View Source

LF_BLK

Block device file type.

Declaration
public const byte LF_BLK = 52
Field Value
Type Description
System.Byte
| Improve this Doc View Source

LF_CHR

Character device file type.

Declaration
public const byte LF_CHR = 51
Field Value
Type Description
System.Byte
| Improve this Doc View Source

LF_CONTIG

Contiguous file type.

Declaration
public const byte LF_CONTIG = 55
Field Value
Type Description
System.Byte
| Improve this Doc View Source

LF_DIR

Directory file type.

Declaration
public const byte LF_DIR = 53
Field Value
Type Description
System.Byte
| Improve this Doc View Source

LF_EXTATTR

Solaris Extended Attribute File

Declaration
public const byte LF_EXTATTR = 69
Field Value
Type Description
System.Byte
| Improve this Doc View Source

LF_FIFO

FIFO (pipe) file type.

Declaration
public const byte LF_FIFO = 54
Field Value
Type Description
System.Byte
| Improve this Doc View Source

LF_GHDR

Posix.1 2001 global extended header

Declaration
public const byte LF_GHDR = 103
Field Value
Type Description
System.Byte
| Improve this Doc View Source

LF_GNU_DUMPDIR

GNU dir dump file type This is a dir entry that contains the names of files that were in the dir at the time the dump was made

Declaration
public const byte LF_GNU_DUMPDIR = 68
Field Value
Type Description
System.Byte
| Improve this Doc View Source

LF_GNU_LONGLINK

Identifies the next file on the tape as having a long link name

Declaration
public const byte LF_GNU_LONGLINK = 75
Field Value
Type Description
System.Byte
| Improve this Doc View Source

LF_GNU_LONGNAME

Identifies the next file on the tape as having a long name

Declaration
public const byte LF_GNU_LONGNAME = 76
Field Value
Type Description
System.Byte
| Improve this Doc View Source

LF_GNU_MULTIVOL

Continuation of a file that began on another volume

Declaration
public const byte LF_GNU_MULTIVOL = 77
Field Value
Type Description
System.Byte
| Improve this Doc View Source

LF_GNU_NAMES

For storing filenames that dont fit in the main header (old GNU)

Declaration
public const byte LF_GNU_NAMES = 78
Field Value
Type Description
System.Byte
| Improve this Doc View Source

LF_GNU_SPARSE

GNU Sparse file

Declaration
public const byte LF_GNU_SPARSE = 83
Field Value
Type Description
System.Byte
| Improve this Doc View Source

LF_GNU_VOLHDR

GNU Tape/volume header ignore on extraction

Declaration
public const byte LF_GNU_VOLHDR = 86
Field Value
Type Description
System.Byte
| Improve this Doc View Source

LF_LINK

Link file type.

Declaration
public const byte LF_LINK = 49
Field Value
Type Description
System.Byte
| Improve this Doc View Source

LF_META

Inode (metadata only) no file content

Declaration
public const byte LF_META = 73
Field Value
Type Description
System.Byte
| Improve this Doc View Source

LF_NORMAL

Normal file type.

Declaration
public const byte LF_NORMAL = 48
Field Value
Type Description
System.Byte
| Improve this Doc View Source

LF_OLDNORM

The "old way" of indicating a normal file.

Declaration
public const byte LF_OLDNORM = 0
Field Value
Type Description
System.Byte
| Improve this Doc View Source

LF_SYMLINK

Symbolic link file type.

Declaration
public const byte LF_SYMLINK = 50
Field Value
Type Description
System.Byte
| Improve this Doc View Source

LF_XHDR

Posix.1 2001 extended header

Declaration
public const byte LF_XHDR = 120
Field Value
Type Description
System.Byte
| Improve this Doc View Source

MAGICLEN

The length of the magic field in a header buffer.

Declaration
public const int MAGICLEN = 6
Field Value
Type Description
System.Int32
| Improve this Doc View Source

MODELEN

The length of the mode field in a header buffer.

Declaration
public const int MODELEN = 8
Field Value
Type Description
System.Int32
| Improve this Doc View Source

MODTIMELEN

The length of the modification time field in a header buffer.

Declaration
public const int MODTIMELEN = 12
Field Value
Type Description
System.Int32
| Improve this Doc View Source

NAMELEN

The length of the name field in a header buffer.

Declaration
public const int NAMELEN = 100
Field Value
Type Description
System.Int32
| Improve this Doc View Source

PREFIXLEN

The length of the name prefix field in a header buffer.

Declaration
public const int PREFIXLEN = 155
Field Value
Type Description
System.Int32
| Improve this Doc View Source

SIZELEN

The length of the size field in a header buffer.

Declaration
public const int SIZELEN = 12
Field Value
Type Description
System.Int32
| Improve this Doc View Source

TMAGIC

The magic tag representing a POSIX tar archive. (would be written with a trailing NULL)

Declaration
public const string TMAGIC = "ustar"
Field Value
Type Description
System.String
| Improve this Doc View Source

UIDLEN

The length of the user id field in a header buffer.

Declaration
public const int UIDLEN = 8
Field Value
Type Description
System.Int32
| Improve this Doc View Source

UNAMELEN

The length of the user name field in a header buffer.

Declaration
public const int UNAMELEN = 32
Field Value
Type Description
System.Int32
| Improve this Doc View Source

VERSIONLEN

The length of the version field in a header buffer.

Declaration
public const int VERSIONLEN = 2
Field Value
Type Description
System.Int32

Properties

| Improve this Doc View Source

Checksum

Get the entry's checksum. This is only valid/updated after writing or reading an entry.

Declaration
public int Checksum { get; }
Property Value
Type Description
System.Int32
| Improve this Doc View Source

DevMajor

Get/set the entry's major device number.

Declaration
public int DevMajor { get; set; }
Property Value
Type Description
System.Int32
| Improve this Doc View Source

DevMinor

Get/set the entry's minor device number.

Declaration
public int DevMinor { get; set; }
Property Value
Type Description
System.Int32
| Improve this Doc View Source

GroupId

Get/set the entry's group id.

Declaration
public int GroupId { get; set; }
Property Value
Type Description
System.Int32
Remarks

This is only directly relevant to linux/unix systems. The default value is zero.

| Improve this Doc View Source

GroupName

Get/set the entry's group name.

Declaration
public string GroupName { get; set; }
Property Value
Type Description
System.String
Remarks

This is only directly relevant to unix systems.

| Improve this Doc View Source

IsChecksumValid

Get value of true if the header checksum is valid, false otherwise.

Declaration
public bool IsChecksumValid { get; }
Property Value
Type Description
System.Boolean
| Improve this Doc View Source

LinkName

The entry's link name.

Declaration
public string LinkName { get; set; }
Property Value
Type Description
System.String
Exceptions
Type Condition
System.ArgumentNullException

Thrown when attempting to set LinkName to null.

| Improve this Doc View Source

Magic

Get/set the entry's magic tag.

Declaration
public string Magic { get; set; }
Property Value
Type Description
System.String
Exceptions
Type Condition
System.ArgumentNullException

Thrown when attempting to set Magic to null.

| Improve this Doc View Source

Mode

Get/set the entry's Unix style permission mode.

Declaration
public int Mode { get; set; }
Property Value
Type Description
System.Int32
| Improve this Doc View Source

ModTime

Get/set the entry's modification time.

Declaration
public DateTime ModTime { get; set; }
Property Value
Type Description
System.DateTime
Remarks

The modification time is only accurate to within a second.

Exceptions
Type Condition
System.ArgumentOutOfRangeException

Thrown when setting the date time to less than 1/1/1970.

| Improve this Doc View Source

Name

Get/set the name for this tar entry.

Declaration
public string Name { get; set; }
Property Value
Type Description
System.String
Exceptions
Type Condition
System.ArgumentNullException

Thrown when attempting to set the property to null.

| Improve this Doc View Source

Size

Get/set the entry's size.

Declaration
public long Size { get; set; }
Property Value
Type Description
System.Int64
Exceptions
Type Condition
System.ArgumentOutOfRangeException

Thrown when setting the size to less than zero.

| Improve this Doc View Source

TypeFlag

Get/set the entry's type flag.

Declaration
public byte TypeFlag { get; set; }
Property Value
Type Description
System.Byte
| Improve this Doc View Source

UserId

The entry's user id.

Declaration
public int UserId { get; set; }
Property Value
Type Description
System.Int32
Remarks

This is only directly relevant to unix systems. The default is zero.

| Improve this Doc View Source

UserName

The entry's user name.

Declaration
public string UserName { get; set; }
Property Value
Type Description
System.String
| Improve this Doc View Source

Version

The entry's version.

Declaration
public string Version { get; set; }
Property Value
Type Description
System.String
Exceptions
Type Condition
System.ArgumentNullException

Thrown when attempting to set Version to null.

Methods

| Improve this Doc View Source

Clone()

Create a new TarHeader that is a copy of the current instance.

Declaration
public object Clone()
Returns
Type Description
System.Object

A new System.Object that is a copy of the current instance.

| Improve this Doc View Source

Equals(Object)

Determines if this instance is equal to the specified object.

Declaration
public override bool Equals(object obj)
Parameters
Type Name Description
System.Object obj

The object to compare with.

Returns
Type Description
System.Boolean

true if the objects are equal, false otherwise.

Overrides
System.Object.Equals(System.Object)
| Improve this Doc View Source

GetAsciiBytes(String, Int32, Byte[], Int32, Int32)

Add a string to a buffer as a collection of ascii bytes.

Declaration
[Obsolete("No Encoding for Name field is specified, any non-ASCII bytes will be discarded")]
public static int GetAsciiBytes(string toAdd, int nameOffset, byte[] buffer, int bufferOffset, int length)
Parameters
Type Name Description
System.String toAdd

The string to add

System.Int32 nameOffset

The offset of the first character to add.

System.Byte[] buffer

The buffer to add to.

System.Int32 bufferOffset

The offset to start adding at.

System.Int32 length

The number of ascii characters to add.

Returns
Type Description
System.Int32

The next free index in the buffer.

| Improve this Doc View Source

GetAsciiBytes(String, Int32, Byte[], Int32, Int32, Encoding)

Add a string to a buffer as a collection of ascii bytes.

Declaration
public static int GetAsciiBytes(string toAdd, int nameOffset, byte[] buffer, int bufferOffset, int length, Encoding encoding)
Parameters
Type Name Description
System.String toAdd

The string to add

System.Int32 nameOffset

The offset of the first character to add.

System.Byte[] buffer

The buffer to add to.

System.Int32 bufferOffset

The offset to start adding at.

System.Int32 length

The number of ascii characters to add.

System.Text.Encoding encoding

String encoding, or null for ASCII only

Returns
Type Description
System.Int32

The next free index in the buffer.

| Improve this Doc View Source

GetHashCode()

Get a hash code for the current object.

Declaration
public override int GetHashCode()
Returns
Type Description
System.Int32

A hash code for the current object.

Overrides
System.Object.GetHashCode()
| Improve this Doc View Source

GetName()

Get the name of this entry.

Declaration
[Obsolete("Use the Name property instead", true)]
public string GetName()
Returns
Type Description
System.String

The entry's name.

| Improve this Doc View Source

GetNameBytes(String, Byte[], Int32, Int32)

Add an entry name to the buffer

Declaration
[Obsolete("No Encoding for Name field is specified, any non-ASCII bytes will be discarded")]
public static int GetNameBytes(string name, byte[] buffer, int offset, int length)
Parameters
Type Name Description
System.String name

The name to add

System.Byte[] buffer

The buffer to add to

System.Int32 offset

The offset into the buffer from which to start adding

System.Int32 length

The number of header bytes to add

Returns
Type Description
System.Int32

The index of the next free byte in the buffer

| Improve this Doc View Source

GetNameBytes(String, Byte[], Int32, Int32, Encoding)

Add an entry name to the buffer

Declaration
public static int GetNameBytes(string name, byte[] buffer, int offset, int length, Encoding encoding)
Parameters
Type Name Description
System.String name

The name to add

System.Byte[] buffer

The buffer to add to

System.Int32 offset

The offset into the buffer from which to start adding

System.Int32 length

The number of header bytes to add

System.Text.Encoding encoding
Returns
Type Description
System.Int32

The index of the next free byte in the buffer

| Improve this Doc View Source

GetNameBytes(String, Int32, Byte[], Int32, Int32)

Add name to the buffer as a collection of bytes

Declaration
public static int GetNameBytes(string name, int nameOffset, byte[] buffer, int bufferOffset, int length)
Parameters
Type Name Description
System.String name

The name to add

System.Int32 nameOffset

The offset of the first character

System.Byte[] buffer

The buffer to add to

System.Int32 bufferOffset

The index of the first byte to add

System.Int32 length

The number of characters/bytes to add

Returns
Type Description
System.Int32

The next free index in the buffer

| Improve this Doc View Source

GetNameBytes(String, Int32, Byte[], Int32, Int32, Encoding)

Add name to the buffer as a collection of bytes

Declaration
public static int GetNameBytes(string name, int nameOffset, byte[] buffer, int bufferOffset, int length, Encoding encoding)
Parameters
Type Name Description
System.String name

The name to add

System.Int32 nameOffset

The offset of the first character

System.Byte[] buffer

The buffer to add to

System.Int32 bufferOffset

The index of the first byte to add

System.Int32 length

The number of characters/bytes to add

System.Text.Encoding encoding

name encoding, or null for ASCII only

Returns
Type Description
System.Int32

The next free index in the buffer

| Improve this Doc View Source

GetNameBytes(StringBuilder, Byte[], Int32, Int32)

Add an entry name to the buffer

Declaration
[Obsolete("No Encoding for Name field is specified, any non-ASCII bytes will be discarded")]
public static int GetNameBytes(StringBuilder name, byte[] buffer, int offset, int length)
Parameters
Type Name Description
System.Text.StringBuilder name

The name to add

System.Byte[] buffer

The buffer to add to

System.Int32 offset

The offset into the buffer from which to start adding

System.Int32 length

The number of header bytes to add

Returns
Type Description
System.Int32

The index of the next free byte in the buffer

| Improve this Doc View Source

GetNameBytes(StringBuilder, Byte[], Int32, Int32, Encoding)

Add an entry name to the buffer

Declaration
public static int GetNameBytes(StringBuilder name, byte[] buffer, int offset, int length, Encoding encoding)
Parameters
Type Name Description
System.Text.StringBuilder name

The name to add

System.Byte[] buffer

The buffer to add to

System.Int32 offset

The offset into the buffer from which to start adding

System.Int32 length

The number of header bytes to add

System.Text.Encoding encoding
Returns
Type Description
System.Int32

The index of the next free byte in the buffer

| Improve this Doc View Source

GetNameBytes(StringBuilder, Int32, Byte[], Int32, Int32)

Add name to the buffer as a collection of bytes

Declaration
public static int GetNameBytes(StringBuilder name, int nameOffset, byte[] buffer, int bufferOffset, int length)
Parameters
Type Name Description
System.Text.StringBuilder name

The name to add

System.Int32 nameOffset

The offset of the first character

System.Byte[] buffer

The buffer to add to

System.Int32 bufferOffset

The index of the first byte to add

System.Int32 length

The number of characters/bytes to add

Returns
Type Description
System.Int32

The next free index in the buffer

| Improve this Doc View Source

GetOctalBytes(Int64, Byte[], Int32, Int32)

Put an octal representation of a value into a buffer

Declaration
public static int GetOctalBytes(long value, byte[] buffer, int offset, int length)
Parameters
Type Name Description
System.Int64 value

the value to be converted to octal

System.Byte[] buffer

buffer to store the octal string

System.Int32 offset

The offset into the buffer where the value starts

System.Int32 length

The length of the octal string to create

Returns
Type Description
System.Int32

The offset of the character next byte after the octal string

| Improve this Doc View Source

ParseBuffer(Byte[])

Parse TarHeader information from a header buffer.

Declaration
[Obsolete("No Encoding for Name field is specified, any non-ASCII bytes will be discarded")]
public void ParseBuffer(byte[] header)
Parameters
Type Name Description
System.Byte[] header

The tar entry header buffer to get information from.

| Improve this Doc View Source

ParseBuffer(Byte[], Encoding)

Parse TarHeader information from a header buffer.

Declaration
public void ParseBuffer(byte[] header, Encoding nameEncoding)
Parameters
Type Name Description
System.Byte[] header

The tar entry header buffer to get information from.

System.Text.Encoding nameEncoding

The System.Text.Encoding used for the Name field, or null for ASCII only

| Improve this Doc View Source

ParseName(Byte[], Int32, Int32)

Parse a name from a header buffer.

Declaration
[Obsolete("No Encoding for Name field is specified, any non-ASCII bytes will be discarded")]
public static string ParseName(byte[] header, int offset, int length)
Parameters
Type Name Description
System.Byte[] header

The header buffer from which to parse.

System.Int32 offset

The offset into the buffer from which to parse.

System.Int32 length

The number of header bytes to parse.

Returns
Type Description
System.String

The name parsed.

| Improve this Doc View Source

ParseName(ReadOnlySpan<Byte>, Encoding)

Parse a name from a header buffer.

Declaration
public static string ParseName(ReadOnlySpan<byte> header, Encoding encoding)
Parameters
Type Name Description
System.ReadOnlySpan<System.Byte> header

The header buffer from which to parse.

System.Text.Encoding encoding

name encoding, or null for ASCII only

Returns
Type Description
System.String

The name parsed.

| Improve this Doc View Source

ParseOctal(Byte[], Int32, Int32)

Parse an octal string from a header buffer.

Declaration
public static long ParseOctal(byte[] header, int offset, int length)
Parameters
Type Name Description
System.Byte[] header

The header buffer from which to parse.

System.Int32 offset

The offset into the buffer from which to parse.

System.Int32 length

The number of header bytes to parse.

Returns
Type Description
System.Int64

The long equivalent of the octal string.

| Improve this Doc View Source

WriteHeader(Byte[])

'Write' header information to buffer provided, updating the check sum.

Declaration
[Obsolete("No Encoding for Name field is specified, any non-ASCII bytes will be discarded")]
public void WriteHeader(byte[] outBuffer)
Parameters
Type Name Description
System.Byte[] outBuffer

output buffer for header information

| Improve this Doc View Source

WriteHeader(Byte[], Encoding)

'Write' header information to buffer provided, updating the check sum.

Declaration
public void WriteHeader(byte[] outBuffer, Encoding nameEncoding)
Parameters
Type Name Description
System.Byte[] outBuffer

output buffer for header information

System.Text.Encoding nameEncoding

The System.Text.Encoding used for the Name field, or null for ASCII only

  • Improve this Doc
  • View Source
In This Article
Back to top Copyright © 2000-2022 SharpZipLib Contributors