TarArchive.CreateEntry

CreateEntry(string, Stream, FileSystemInfo)

Create single entry within the archive.

public TarEntry CreateEntry(string name, Stream source, FileSystemInfo fileInfo = null)
ParameterTypeDescription
nameStringThe name of the entry.
sourceStreamThe input stream for the entry.
fileInfoFileSystemInfoThe metadata of file or folder to be compressed.

Return Value

Tar entry instance.

Exceptions

exceptioncondition
PathTooLongExceptionname is too long for tar as of IEEE 1003.1-1998 standard.
ArgumentExceptionFile name, as a part of name, exceeds 100 symbols.

Remarks

The entry name is solely set within name parameter. The file name provided in fileInfo parameter does not affect the entry name.

fileInfo can refer to DirectoryInfo if the entry is directory.

Examples

using (var archive = new TarArchive())
{
   archive.CreateEntry("bytes", new MemoryStream(new byte[] {0x00, 0xFF}));
   archive.Save(tarFile);
}

See Also


CreateEntry(string, FileInfo, bool)

Create single entry within the archive.

public TarEntry CreateEntry(string name, FileInfo fileInfo, bool openImmediately = false)
ParameterTypeDescription
nameStringThe name of the entry.
fileInfoFileInfoThe metadata of file or folder to be compressed.
openImmediatelyBooleanTrue if open the file immediately, otherwise open the file on archive saving.

Return Value

Tar entry instance.

Exceptions

exceptioncondition
PathTooLongExceptionname is too long for tar as of IEEE 1003.1-1998 standard.
ArgumentExceptionFile name, as a part of name, exceeds 100 symbols.

Remarks

The entry name is solely set within name parameter. The file name provided in fileInfo parameter does not affect the entry name.

fileInfo can refer to DirectoryInfo if the entry is directory.

If the file is opened immediately with openImmediately parameter it becomes blocked until archive is disposed.

Examples

FileInfo fi = new FileInfo("data.bin");
using (var archive = new TarArchive())
{
   archive.CreateEntry("data.bin", fi);
   archive.Save(tarFile);
}

See Also


CreateEntry(string, string, bool)

Create single entry within the archive.

public TarEntry CreateEntry(string name, string path, bool openImmediately = false)
ParameterTypeDescription
nameStringThe name of the entry.
pathStringPath to file to be compressed.
openImmediatelyBooleanTrue if open the file immediately, otherwise open the file on archive saving.

Return Value

Tar entry instance.

Exceptions

exceptioncondition
ArgumentNullExceptionpath is null.
SecurityExceptionThe caller does not have the required permission to access.
ArgumentExceptionThe path is empty, contains only white spaces, or contains invalid characters. - or - File name, as a part of name, exceeds 100 symbols.
UnauthorizedAccessExceptionAccess to file path is denied.
PathTooLongExceptionThe specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters. - or - name is too long for tar as of IEEE 1003.1-1998 standard.
NotSupportedExceptionFile at path contains a colon (:) in the middle of the string.

Remarks

The entry name is solely set within name parameter. The file name provided in path parameter does not affect the entry name.

If the file is opened immediately with openImmediately parameter it becomes blocked until archive is disposed.

Examples

using (var archive = new TarArchive())
{
    archive.CreateEntry("first.bin", "data.bin");
    archive.Save(outputTarFile);
}

See Also