* Adds a file to this zip. * * @param {string} filePath path to the file to add. * @param {string=} zipPath path to the file in the zip archive, defaults * to the basename of `filePath`. * @return {!Promise<?>} a promise that will resolve when added.
(filePath, zipPath = path.basename(filePath))
| 44 | * @return {!Promise<?>} a promise that will resolve when added. |
| 45 | */ |
| 46 | addFile(filePath, zipPath = path.basename(filePath)) { |
| 47 | let add = Promise.all([io.read(filePath), fs.stat(filePath)]).then(([buffer, stats]) => |
| 48 | this.z_.file(/** @type {string} */ (zipPath.replace(/\\/g, '/')), buffer, { |
| 49 | date: stats.mtime, // preserve file's "last modified" value |
| 50 | }), |
| 51 | ) |
| 52 | this.pendingAdds_.add(add) |
| 53 | return add.then( |
| 54 | () => this.pendingAdds_.delete(add), |
| 55 | (e) => { |
| 56 | this.pendingAdds_.delete(add) |
| 57 | throw e |
| 58 | }, |
| 59 | ) |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Recursively adds a directory and all of its contents to this archive. |
no test coverage detected