ObjectZipFile
The ZipFile object iszipAn important object in the format file compression and decompression module, which provideszipRead and write access to files
ZipFile objects inherit fromStreamobject, so it can be passedStreamOperate in the same way as objects.
Commonly used static functions are:
- zip.open:Open azipfile or stream
- zip.isZipFile: Determine whether the file iszipdocument
- fs.setZipFS:set upzipfile virtual file system
- fs.clearZipFS: clearzipfile virtual file system
Common instance functions and methods of ZipFile objects are:
- NArrayZipFile.namelist(): Get a list of file names
- NObjectZipFile.getinfo(String member): Get file information
- Buffer ZipFile.read(String member, String password = ""): Read the specified file
- NArrayZipFile.readAll(String password = ""): Read all files
- voidZipFile.extract(String member, Stringpath, String password = ""): Extract the file to the specified path
- voidZipFile.extract(String member,SeekableStreamstrm, String password = ""): Decompress the file into the stream
- voidZipFile.extractAll(Stringpath, String password = ""): Extract all files to the specified path
- voidZipFile.write(String filename, String inZipName, String password = ""): Write the specified file to the compressed file
- voidZipFile.write(Bufferdata, String inZipName, String password = ""): Write the specified file to the compressed file
- voidZipFile.write(SeekableStreamstrm, String inZipName, String password = ""): Write the specified file to the compressed file
- voidZipFile.close(): close openzipdocument
The code example is as follows:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15var zip = require('zip');
var path = require('path');
var fs = require('fs');
var zipfile = zip.open(path.join(__dirname, 'unzip_test.zip'), 'w');
// write a file
var buf = new Buffer('test data');
zipfile.write(buf, 'test.txt');
// read a file
buf = zipfile.read("unzip_test.js");
console.log(buf);
zipfile.close();
inheritance relationship
member function
namelist
Get a list of file names
1NArray ZipFile.namelist() async;
Return results:
- NArray, returns a list object containing file names
infolist
Get file information list
1NArray ZipFile.infolist() async;
Return results:
- NArray, returns a list object containing file information
File information includes fields: filename, date, compress_type, compress_size, file_size, password, data
getinfo
Get file information
1NObject ZipFile.getinfo(String member) async;
Call parameters:
- member: String, specifies the file name to obtain information from
Return results:
- NObject, returns the file information object
File information includes fields: filename, date, compress_type, compress_size, file_size, password, data
read
Returns the data read from the compressed file
1
2Buffer ZipFile.read(String member,
String password = "") async;
Call parameters:
- member: String, specifies the file name to be read
- password: String, decompression password, no password by default
Return results:
- Buffer, returns all the data of the file
readAll
Unzip all files
1NArray ZipFile.readAll(String password = "") async;
Call parameters:
- password: String, decompression password, no password by default
Return results:
- NArray, a list containing all file data and information
extract
Unzip the specified file
1
2
3ZipFile.extract(String member,
String path,
String password = "") async;
Call parameters:
- member: String, specify the file name to be decompressed
- path: String, specify the path to be decompressed
- password: String, decompression password, no password by default
Decompress the specified file to the stream
1
2
3ZipFile.extract(String member,
SeekableStream strm,
String password = "") async;
Call parameters:
- member: String, specify the file name to be decompressed
- strm:SeekableStream, specify the stream to be decompressed
- password: String, decompression password, no password by default
extractAll
Unzip all files to the specified path
1
2ZipFile.extractAll(String path,
String password = "") async;
Call parameters:
- path: String, specify the path to be decompressed
- password: String, decompression password, no password by default
write
Write the specified file to the compressed file
1
2
3ZipFile.write(String filename,
String inZipName,
String password = "") async;
Call parameters:
- filename: String, specifies the file to be written
- inZipName: String, compressed inzipfile name within file
- password: String, decompression password, no password by default
Write the specified file to the compressed file
1
2
3ZipFile.write(Buffer data,
String inZipName,
String password = "") async;
Call parameters:
- data:Buffer, specify the file data to be written
- inZipName: String, compressed inzipfile name within file
- password: String, decompression password, no password by default
Write the specified file to the compressed file
1
2
3ZipFile.write(SeekableStream strm,
String inZipName,
String password = "") async;
Call parameters:
- strm:SeekableStream, specifies the file data stream to be written to
- inZipName: String, compressed inzipfile name within file
- password: String, decompression password, no password by default
close
closed openzipdocument
1ZipFile.close() async;
toString
Returns the string representation of the object. Generally, "[Native Object]" is returned. The object can be re-implemented according to its own characteristics.
1String ZipFile.toString();
Return results:
- String, returns the string representation of the object
toJSON
Returns a JSON format representation of the object, generally returning a collection of readable properties defined by the object.
1Value ZipFile.toJSON(String key = "");
Call parameters:
- key: String, not used
Return results:
- Value, returns a value containing JSON serializable