# FileSystemManager.readZipEntry(Object object)

Start from base library version 2.17.3. Please remaining backward compatible.

with Promise style call: Not supported

Mini Program plugin: Support, need to Mini Program base library version no less than 2.19.2

Read the files in the archive

# parameter

# Object object

| attribute | type | Default values | Required | Introductions | | 初始值 | ---- | ------ | -------- | ---- | | filePath | string | | yes | Path of the compressed packet to read (Local path) | | encoding | string | | no | Uniformly specifies the character encoding for reading files, only in the entries Valid when the value is "all." if entries Value is "all" and is not passed Encoding, the ArrayBuffer Format to read the binary contents of a file | | entries | Array.&ltObject&gt/'all' | | yes | List of files in the zip package to read when "all" is passed in All files in the compressed package are read | | success | function | | no | Interface calls the successful callback function | | fail | function | | no | Interface calls failed callback functions | | complete | function | | no | Callback function at the end of an interface call (both successful and unsuccessful calls are executed) |

object.encoding Legal value

value Introductions Minimum version
ascii
base64
binary
hex
ucs2 Read in small endorder
ucs-2 Read in small endorder
Utf16le Read in small endorder
utf-16le Read in small endorder
utf-8
utf8
latin1

object.entries Structure

attribute type Default values Required Introductions
path string yes Archive Path
encoding string no Specifies the character encoding for the read file, if the Encoding, the ArrayBuffer Format to read the binary contents of a file
position number no Start reading from the specified location in the file or from the file header if not specified. Read range should be left closed and right open range [position, position+length). Valid Scope:[0, fileLength - 1]. Unit: byte
length number no Specifies the length of the file, if not specified, read to the end of the document. Scope of validity:[1, fileLength]. Unit: byte

encoding Legal value

value Introductions Minimum version
ascii
base64
binary
hex
ucs2 Read in small endorder
ucs-2 Read in small endorder
Utf16le Read in small endorder
utf-16le Read in small endorder
utf-8
utf8
latin1

# object.success callback

# 初始值
# Object res
attribute type Introductions
entries Object File read results. res.entries Is an object, key is the file path, and value is the object. FileItem Represents the result of reading the file. Each FileItem Contain data (document content) and errMsg (Error message) Property.

res.entries Structure

attribute type Introductions
&lbrackpath: string&rbrack Object File path

res.entries&lbrackpath&rbrack Structure

attribute type Introductions
data string/ArrayBuffer Document content
errMsg string Error message

# object.fail callback

# parameter
# Object res
attribute type Introductions
errMsg string Error message

res.errMsg Legal value

value Introductions Minimum version
fail No such file or directory, open ${filePath} Specified filePath Directory does not exist
fail permission denied, open ${dirPath} Specified filePath Path not read
fail sdcard not mounted Android sdcard Mount failure

# sample code

const fs = wx.getFileSystemManager()
// Read one or more files in a zip
fs.readZipEntry({
  filePath: 'wxfile://from/to.zip',
  entries: [{
    path: 'some_folder/my_file.txt', // Zip file path
    encoding: 'utf-8', // Specifies the character encoding for the read file, if the Encoding, the ArrayBuffer Format to read the binary contents of a file
    position: 0, // Start reading from the specified location in the file or from the file header if not specified. Read range should be left closed and right open range [position, position+length). Valid Scope:[0, fileLength - 1]. Unit: byte
    length: 10000, // Specifies the length of the file, if not specified, read to the end of the document. Scope of validity:[1, fileLength]. Unit: byte
  }, {
    path: 'other_folder/orther_file.txt', // Zip file path
  }],
  success(res) {
    console.log(res.entries)
    // res.entries === {
    //     'some_folder/my_file.txt': {
    //         errMsg: 'readZipEntry:ok',
    //         data: Post posted: 'xxxxxx'
    //     },
    //     'other_folder/orther_file.txt': {
    //         data: (ArrayBuffer)
    //     }
    // }
  },
  fail(res) {
    console.log(res.errMsg)
  },
})

// Read all files in zip. Allows specifying uniform encoding. Position and length are no longer allowed, default to 0 and file length, respectively
fs.readZipEntry({
  filePath: 'wxfile://from/to.zip',
  entries: 'all'
  encoding: 'utf-8', // Uniform character encoding specified read file, if not Encoding, the ArrayBuffer Format to read the binary contents of a file
  success(res) {
    console.log(res.entries)
    // res.entries === {
    //     'some_folder/my_file.txt': {
    //         errMsg: 'readZipEntry:ok',
    //         data: Post posted: 'xxxxxx'
    //     },
    //     'other_folder/orther_file.txt': {
    //         errMsg: 'readZipEntry:ok',
    //         data: Post posted: 'xxxxxx'
    //     }
    //  }
  },
  fail(res) {
    console.log(res.errMsg)
  },
})