Advertisement
Guest User

Untitled

a guest
Apr 25th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. const fs = require('fs')
  2. const archiver = require('archiver')
  3.  
  4. /**
  5. * 文件夹压缩
  6. * @param {string} src 源文件夹绝对路径
  7. * @return {string} 压缩后的文件路径
  8. */
  9. module.exports = src => {
  10. return new Promise((resolve, reject) => {
  11. const dist = `${src}.zip`
  12. const output = fs.createWriteStream(dist)
  13. const archive = archiver('zip')
  14.  
  15. archive.pipe(output)
  16. archive.glob('**/*', {cwd: src, expand: true, dot: true})
  17. archive.finalize()
  18.  
  19. output.on('close', () => resolve(dist))
  20. archive.on('error', err => reject(err))
  21. })
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement