-
Notifications
You must be signed in to change notification settings - Fork 0
Home
-
adm-zip.js
- constructor(filePath)
- getEntries(): Array
- getEntry(name): ZipObject
- readFile(entry): Buffer
- readFileAsync(entry, callback)
- readAsText(entry, encoding = 'utf8')
- readAsTextAsync(entry, callback, encoding = 'utf8')
- deleteFile(entry)
- addZipComment(comment)
- getZipComment(): String
- addZipEntryComment(entry, comment)
- getZipEntryComment(entry): String
- updateFile(entry, content)
- addLocalFile(localPath, zipPath)
- addLocalFolder(localPath, zipPath)
- addFile(entryName, content, comment, attr)
- extractEntryTo(entry, targetPath, maintainEntryPath, overwrite = false, outFileName)
- extractAllTo(targetPath, overwrite = false)
- writeZip(targetFileName)
- toBuffer(onSuccess, onFail, onItemStart, onItemEnd): Buffer
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.
Updates the content of an existing entry inside the archive. The zip must be rewritten after updating the content.
The entry
argument can be either a ZipEntry object or String with the entry name.
Adds a file from the disk to the archive.
Adds a local directory and all its nested files and directories to the archive.
Allows you to programmatically create a entry (file or directory) in the zip file.
If you want to create a directory the entryName
must end in / and a null buffer should be provided.
comment
and attributes
are optional.
<void> extractEntryTo(Object entry, String targetPath, Boolean maintainEntryPath = true, Boolean overwrite = false, String outFileName)
Extracts 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);
// will extract the file newname.txt from the archive to /home/user/myfile.txt
zip.extractEntryTo("folder/subfolder/myfile.txt", "/home/user/", false, true, "newname.txt");
Extracts the entire archive to location specified 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.
Writes the newly created zip file to disk at the specified location or if a zip was opened and no targetFileName
is provided, it will overwrite the opened zip.
Returns the content of the entire zip file as a Buffer object. In async mode:
onSuccess(Buffer buffer);
onFail(String error);
onItemStart(String fileName);
onItemEnd(String fileName);