dreamworkAPI
Ctrl K
GitHub
classDocs / Tar

Tar

classsharedmenusource
Object → Tar

The tar (.tar) archive.

Parses POSIX ustar, pax and GNU archives (long names and base-256 numbers), gzip compressed archives are decompressed on parse.

Builds ustar archives, long paths and out of range values are written with pax headers.

lua
local tar = Tar()
tar:addDirectory( "docs" )
tar:addFile( "docs/readme.txt", "hello" )

local data = tar:compile()
print( Tar( data ):readFile( "docs/readme.txt" ) ) -- hello

Constructor

Tar(data: string?): Tar

Fields

NameTypeDescription
filesTar.File[]The entries of the archive.
file_countintegerThe number of entries.
file_indexestable<string, integer>The indexes of entries in files by their paths.
gzippedbooleantrue if the parsed archive was gzip compressed.
datastring | nilThe parsed archive data, the content of not yet read entries.

Methods

addDirectoryAdds the directory to the archive, replaces the existing entry with the same path.
addFileAdds the regular file to the archive, replaces the existing entry with the same path.
addSymlinkAdds the symbolic link to the archive, replaces the existing entry with the same path.
compileBuilds the .tar data of the archive.
getFileReturns the entry of the archive.
parseReplaces the archive with the parsed .tar or .tar.gz data.
readFileReturns the content of the entry of the archive.
removeFileRemoves the entry from the archive.

#Tar:addDirectory

sharedmenusource
function Tar:addDirectory(directory_path: string, mode?: integer): Tar.File

Adds the directory to the archive, replaces the existing entry with the same path.

Parameters
NameTypeDescription
directory_pathstringThe path of the directory inside of the archive, / is appended if missing.
modeoptionalintegerThe permission bits, 493 (0755) by default.
Returns
TypeNameDescription
Tar.FilefileThe added directory.

#Tar:addFile

sharedmenusource
function Tar:addFile(file_path: string, content: string, mode?: integer): Tar.File

Adds the regular file to the archive, replaces the existing entry with the same path.

Parameters
NameTypeDescription
file_pathstringThe path of the file inside of the archive, e.g. docs/readme.txt.
contentstringThe file content.
modeoptionalintegerThe permission bits, 420 (0644) by default.
Returns
TypeNameDescription
Tar.FilefileThe added file.

#Tar:compile

sharedmenunodiscardsource
function Tar:compile(): string

Builds the .tar data of the archive.

Use gzip.compress on the result to get .tar.gz.

Returns
TypeNameDescription
stringdataThe .tar data.

#Tar:getFile

sharedmenunodiscardsource
function Tar:getFile(file_path: string): Tar.File | nil

Returns the entry of the archive.

Parameters
NameTypeDescription
file_pathstringThe path of the entry inside of the archive.
Returns
TypeNameDescription
Tar.File | nilfileThe entry, nil if there is no such entry.

#Tar:parse

sharedmenusource
function Tar:parse(data: string)

Replaces the archive with the parsed .tar or .tar.gz data.

File contents are not copied, they are read from the data on demand by readFile.

Parameters
NameTypeDescription
datastringThe .tar or .tar.gz data.

#Tar:readFile

sharedmenunodiscardsource
function Tar:readFile(file_path: string): string | nil

Returns the content of the entry of the archive.

Parameters
NameTypeDescription
file_pathstringThe path of the entry inside of the archive.
Returns
TypeNameDescription
string | nilcontentThe content, nil if there is no such entry.

#Tar:removeFile

sharedmenusource
function Tar:removeFile(file_path: string): boolean

Removes the entry from the archive.

Parameters
NameTypeDescription
file_pathstringThe path of the entry inside of the archive.
Returns
TypeNameDescription
booleanremovedtrue if the entry was removed, false if there is no such entry.
Generated from the dreamwork meta branch.