MTA:Eir/FileSystem/createArchiveTranslator

From Multi Theft Auto: Wiki
Jump to navigation Jump to search

This function creates a FileSystem archive translator. A FileSystem archive translator is a virtual FileSystem that grants access to the contents of archives. You can browse archives the same way as you would with native OS directories. The archive implementations usually cache their operations inside of the OS temp directory.

Currently, only .zip archives are supported.

Syntax

atranslator fsnamespace.createArchiveTranslator ( file fileHandle )

Arguments

  • fileHandle: a MTA:Eir FileSystem file/stream class that contains the archive.

Returns

This function returns the FileSystem translator that grants access to contents of an archive.

Remarks

This function is currently unavailable in the fileSystem.dll module.

Example

Click to collapse [-]
Client

This snippet lists the contents of a .zip archive.

-- Opens the file link to our .zip archive.
-- The input fileStream can actually be any file/stream class that is exported to the script.
-- The implementation is allowed to throw exceptions if a file/stream class is incompatible.
local zipFile = fileOpen( "theArchive.zip", "rb" );

-- Check that we can access that .zip archive.
if not ( zipFile ) then
    outputDebugString( "could not open theArchive.zip" );
    return false;
end

-- Try to open a content link to the .zip archive.
-- This operation will fail is the archive is not valid.
local zipTranslator = fileOpenArchive( zipFile );

if not ( zipTranslator ) then
    outputDebugString( "could not access the contents of theArchive.zip" );
    outputDebugString( "the archive could be damaged" );
    return false;
end

-- This table shall contain all filenames of the archive.
local fileEntries = {};

local function fileIterator( filePath )
    -- Add the filename to our list.
    table.insert( fileEntries, zipTranslator.relPathRoot( filePath ) );
end

zipTranslator.scanDirEx( "/", "*", nil, fileIterator, true );

-- List the filenames on the chatbox.
for m,n in ipairs( fileEntries ) do
    outputChatBox( n );
end

FileSystem Namespace Functions

FileSystem Translator Functions

FileSystem Archive Translator Functions