audiobookshelf/server/libs/archiver/lib/plugins/zip.js
2022-07-08 18:11:09 -05:00

121 lines
4.1 KiB
JavaScript

/**
* ZIP Format Plugin
*
* @module plugins/zip
* @license [MIT]{@link https://github.com/archiverjs/node-archiver/blob/master/LICENSE}
* @copyright (c) 2012-2014 Chris Talkington, contributors.
*/
var engine = require('../../zip-stream');
var util = require('../../archiverUtils');
/**
* @constructor
* @param {ZipOptions} [options]
* @param {String} [options.comment] Sets the zip archive comment.
* @param {Boolean} [options.forceLocalTime=false] Forces the archive to contain local file times instead of UTC.
* @param {Boolean} [options.forceZip64=false] Forces the archive to contain ZIP64 headers.
* @param {Boolean} [options.namePrependSlash=false] Prepends a forward slash to archive file paths.
* @param {Boolean} [options.store=false] Sets the compression method to STORE.
* @param {Object} [options.zlib] Passed to [zlib]{@link https://nodejs.org/api/zlib.html#zlib_class_options}
*/
var Zip = function (options) {
if (!(this instanceof Zip)) {
return new Zip(options);
}
options = this.options = util.defaults(options, {
comment: '',
forceUTC: false,
namePrependSlash: false,
store: false
});
this.supports = {
directory: true,
symlink: true
};
this.engine = new engine(options);
};
/**
* @param {(Buffer|Stream)} source
* @param {ZipEntryData} data
* @param {String} data.name Sets the entry name including internal path.
* @param {(String|Date)} [data.date=NOW()] Sets the entry date.
* @param {Number} [data.mode=D:0755/F:0644] Sets the entry permissions.
* @param {String} [data.prefix] Sets a path prefix for the entry name. Useful
* when working with methods like `directory` or `glob`.
* @param {fs.Stats} [data.stats] Sets the fs stat data for this entry allowing
* for reduction of fs stat calls when stat data is already known.
* @param {Boolean} [data.store=ZipOptions.store] Sets the compression method to STORE.
* @param {Function} callback
* @return void
*/
Zip.prototype.append = function (source, data, callback) {
this.engine.entry(source, data, callback);
};
/**
* @return void
*/
Zip.prototype.finalize = function () {
this.engine.finalize();
};
/**
* @return this.engine
*/
Zip.prototype.on = function () {
return this.engine.on.apply(this.engine, arguments);
};
/**
* @return this.engine
*/
Zip.prototype.pipe = function () {
return this.engine.pipe.apply(this.engine, arguments);
};
/**
* @return this.engine
*/
Zip.prototype.unpipe = function () {
return this.engine.unpipe.apply(this.engine, arguments);
};
module.exports = Zip;
/**
* @typedef {Object} ZipOptions
* @global
* @property {String} [comment] Sets the zip archive comment.
* @property {Boolean} [forceLocalTime=false] Forces the archive to contain local file times instead of UTC.
* @property {Boolean} [forceZip64=false] Forces the archive to contain ZIP64 headers.
* @prpperty {Boolean} [namePrependSlash=false] Prepends a forward slash to archive file paths.
* @property {Boolean} [store=false] Sets the compression method to STORE.
* @property {Object} [zlib] Passed to [zlib]{@link https://nodejs.org/api/zlib.html#zlib_class_options}
* to control compression.
* @property {*} [*] See [zip-stream]{@link https://archiverjs.com/zip-stream/ZipStream.html} documentation for current list of properties.
*/
/**
* @typedef {Object} ZipEntryData
* @global
* @property {String} name Sets the entry name including internal path.
* @property {(String|Date)} [date=NOW()] Sets the entry date.
* @property {Number} [mode=D:0755/F:0644] Sets the entry permissions.
* @property {Boolean} [namePrependSlash=ZipOptions.namePrependSlash] Prepends a forward slash to archive file paths.
* @property {String} [prefix] Sets a path prefix for the entry name. Useful
* when working with methods like `directory` or `glob`.
* @property {fs.Stats} [stats] Sets the fs stat data for this entry allowing
* for reduction of fs stat calls when stat data is already known.
* @property {Boolean} [store=ZipOptions.store] Sets the compression method to STORE.
*/
/**
* ZipStream Module
* @external ZipStream
* @see {@link https://www.archiverjs.com/zip-stream/ZipStream.html}
*/