Object built-in object

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:

Common instance functions and methods of ZipFile objects are:

The code example is as follows:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
var 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

1
NArray ZipFile.namelist() async;

Return results:

  • NArray, returns a list object containing file names

infolist

Get file information list

1
NArray 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

1
NObject 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 2
Buffer 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

1
NArray 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 3
ZipFile.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 3
ZipFile.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 2
ZipFile.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 3
ZipFile.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 3
ZipFile.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 3
ZipFile.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

1
ZipFile.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.

1
String 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.

1
Value ZipFile.toJSON(String key = "");

Call parameters:

  • key: String, not used

Return results:

  • Value, returns a value containing JSON serializable