-
Notifications
You must be signed in to change notification settings - Fork 375
ADM ZIP
ADM-ZIP is the main and the only class that should be used. It provides almost all methods required for you to use with a zip archive.
var Zip = require("adm-zip");
The class constructor can have one or no arguments specified.
If a argument of type String is provided, the class will try to read the file at filePath
and parse it as a zip.
If no argument is specified, then a new in memory zip will be created
Examples:
// loads and parses existing zip file local_file.zip
var zip = new Zip("local_file.zip");
// creates new in memory zip
var zip = new Zip();
Returns an array of ZipEntry objects representing the files and folders inside the archive
Returns a ZipEntry object representing the file or folder specified by name
.
Extracts the given entry
from the archive and returns the content as a Buffer object.
The entry
argument can be either a ZipEntry object or String with the entry name.
Asynchronous readFile
Extracts the given entry
from the archive and returns the content as plain text in the given encoding
. If no encoding is specified, utf8 will be used
The entry
argument can be either a ZipEntry object or String with the entry name.
Examples:
// loads and parses existing zip file local_file.zip
var zip = new Zip("local_file.zip");
// get all entries and iterate them
zip.getEntries().forEach(function(entry) {
var entryName = entry.entryName;
var decompressedData = zip.readFile(entry); // decompressed buffer of the entry
console.log(zip.readAsText(entry)); // outputs the decompressed content of the entry
});
Asynchronous readAsText
Remove the entry from the file or the entry and all it's nested directories and files if the given entry is a directory
The entry
argument can be either a ZipEntry object or String with the entry name.
Adds a comment to the zip. The zip must be rewritten after adding the comment.
Returns the zip comment
Adds a comment to a specified entry
. The zip must be rewritten after adding the comment and the comment cannot exceed 65535 characters in length.
The entry
argument can be either a ZipEntry object or String with the entry name.
Returns the comment of the specified entry
.
The entry
argument can be either a ZipEntry object or String with the entry name.
[void] extractEntryTo(Object entry, String targetPath, Boolean maintainEntryPath = true, Boolean overwrite = false)
Etracts the given entry
to the given targetPath
. If the entry
is a directory inside the archive, the entire directory and it's subdirectories will be extracted
The entry
argument can be either a ZipEntry object or String with the entry name.
If maintainEntryPath
is TRUE and the entry is inside a folder, the entry folder will be created in targetPath as well.
If the files to be extracted already exist at the target path, the files may be overwritten if specified so by the overwrite
argument
// will extract the file myfile.txt from the archive to /home/user/folder/subfolder/myfile.txt
zip.extractEntryTo("folder/subfolder/myfile.txt", "/home/user/", true, true);
// will extract the file myfile.txt from the archive to /home/user/myfile.txt
zip.extractEntryTo("folder/subfolder/myfile.txt", "/home/user/", false, true);
Extracts the entire archive to location specifed by targetPath
.
If the files to be extracted already exist at the target path, the files may be overwritten if specified so by the overwrite
argument