mZip

mZip

new mZip() → {Object}

Source:

Zip處理

Example
import wz from 'w-zip'

let fpUnzip = './testData/outputZip'
let fpUnzipExtract = fpUnzip + '/extract'

let fpSrc1 = './testData/input/file1(中文).txt'
let fpZip1 = fpUnzip + '/test1.zip'

let fpSrc2 = './testData/input/folder1'
let fpZip2 = fpUnzip + '/test2.zip'
let fpZip2PW = fpUnzip + '/test2PW.zip'
let pw = 'abc'

async function test() {

    //zipFile
    console.log('zipFile before')
    console.log('zipFile', await wz.mZip.zipFile(fpSrc1, fpZip1))
    console.log('zipFile after')

    //zipFolder
    console.log('zipFolder before')
    console.log('zipFolder', await wz.mZip.zipFolder(fpSrc2, fpZip2))
    console.log('zipFolder after')

    //zipFolder with password
    console.log('zipFolder with password before')
    console.log('zipFolder with password', await wz.mZip.zipFolder(fpSrc2, fpZip2PW, { pw }))
    console.log('zipFolder with password after')

    //unzip
    console.log('unzip1 before')
    console.log('unzip1', await wz.mZip.unzip(fpZip1, fpUnzipExtract + '/test1'))
    console.log('unzip1 after')

    //unzip
    console.log('unzip2 before')
    console.log('unzip2', await wz.mZip.unzip(fpZip2, fpUnzipExtract + '/test2'))
    console.log('unzip2 after')

    //unzip with password
    console.log('unzip2 with password before')
    console.log('unzip2 with password', await wz.mZip.unzip(fpZip2PW, fpUnzipExtract + '/test2PW', { pw }))
    console.log('unzip2 with password after')

}
test()
    .catch((err) => {
        console.log(err)
    })

// zipFile before
// zipFile done: ./testData/outputZip/test1.zip
// zipFile after
// zipFolder before
// zipFolder done: ./testData/outputZip/test2.zip
// zipFolder after
// zipFolder with password before
// zipFolder with password done: ./testData/outputZip/test2PW.zip
// zipFolder with password after
// unzip1 before
// unzip1 done: ./testData/outputZip/extract/test1
// unzip1 after
// unzip2 before
// unzip2 done: ./testData/outputZip/extract/test2
// unzip2 after
// unzip2 with password before
// unzip2 with password done: ./testData/outputZip/extract/test2PW
// unzip2 with password after
Returns:

回傳壓縮物件,可使用函數zipFile、zipFolder、unzip

Type
Object

Methods

(async, static) unzip(fpSrc, fpTar, optopt) → {Promise}

Source:

解壓縮檔案至資料夾

Parameters:
Name Type Attributes Default Description
fpSrc String

輸入解壓縮來源檔案位置字串

fpTar String

輸入解壓縮目標資料夾位置字串

opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Default Description
pw String <optional>
''

輸入解壓縮密碼字串,預設''

Returns:

回傳Promise,resolve為成功資訊,reject為失敗資訊

Type
Promise

(async, static) zipFile(fpSrc, fpTar, optopt) → {Promise}

Source:

壓縮檔案

Parameters:
Name Type Attributes Default Description
fpSrc String

輸入壓縮來源檔案位置字串

fpTar String

輸入壓縮目標檔案位置字串

opt Object <optional>
{}

輸入設定物件,預設{}

Properties
Name Type Attributes Description
level Integer <optional>

輸入壓縮程度整數,範圍為0至9,0為不壓縮而9為最高壓縮,預設9

pw String <optional>

輸入壓縮密碼字串,預設''

Returns:

回傳Promise,resolve為成功資訊,reject為失敗資訊

Type
Promise

(async, static) zipFolder(fpSrc, fpTar, level) → {Promise}

Source:

壓縮資料夾

Parameters:
Name Type Description
fpSrc String

輸入壓縮來源資料夾位置字串

fpTar String

輸入壓縮目標資料夾位置字串

level Integer

輸入壓縮程度整數,範圍為0至9,0為不壓縮而9為最高壓縮,預設9

Returns:

回傳Promise,resolve為成功資訊,reject為失敗資訊

Type
Promise