Skip to content
Alex Barnier edited this page Mar 8, 2018 · 7 revisions

Content(string: archivePath, function: callback)

Content() will list all the files and folders in an archive, as well as give some information about these entries.

ArchiveManager.Content('path/to/archive',function(error,files){
    if(error){
        console.error(error);
        return;
    }
    //files: array of objects in format : {string: name, number: size, boolean: directory}
});

Create(array: newFiles, ?array: newData, string: outputPath, function: callback)

Create() will create a new archive file at outputPath with the files specified in the newFiles array.

ArchiveManager.Create(['path/to/file/1','path/to/file/2',...],'path/to/archive', function(error,outcome){
    //outcome: true if the creation was successful (usually true, if there was no errors)
});

You can create a new archive using buffers as well:

ArchiveManager.Create(['name/of/file/1','name/of/file/2',...],[buffer_file_1, buffer_file_2,...], 'path/to/archive', function(error,outcome){
});

Append(array: newFiles, ?array: newData, string archivePath, function: callback)

NOTE: In-Place edits are currently not supported by libarchive, so this could be very slow for large archives.

Append() works like Create(), except the data already in the archive will be preserved. Any file in the archive with the same name as one you wish to append will be overwritten.

ArchiveManager.Append(['path/to/file/1','path/to/file/2',...], 'path/to/archive', function(error,outcome){
    //outcome: true if the appending was successful (usually true, if there was no errors)
});

Append() will also work with buffers:

ArchiveManager.Append(['name/of/file/1','name/of/file/2',...], [buffer_file_1, buffer_file_2,...], 'path/to/archive', function(error,outcome){
});

Extract(string: archivePath, string: outputPath, function: callback)

Extract() will put all the contents of the archive speified by archivePath to outputPath

ArchiveManager.Extract('path/to/archive', 'path/to/output', function(error,outcome){
    //outcome: true if the extraction was successful (usually true, if there was no errors)
});

Read(string: internalPath, string: archivePath, function: callback)

Read() will allow you to copy a file from an archive into memory to be used any way a buffer can. This is particullarly useful for JSON files and images.

ArchiveManager.Read('path/in/archive','path/to/archive', function(error,data){
    //data: buffer containing the contents of the file
});

Remove(array: fileNames, string: archivePath, function: callback)

Remove() will delete all the files in the archive specified in teh fileNames array.

ArchiveManager.Remove(['name/of/file/1','name/of/file/2',...],'path/to/archive', function(error,outcome){
    //outcome: true if the extraction was successful (usually true, if there was no errors)
});