Initial commit

This commit is contained in:
jiapengyu
2026-07-27 13:37:48 +08:00
commit ecba71e2a5
39123 changed files with 5989154 additions and 0 deletions
+79
View File
@@ -0,0 +1,79 @@
import { Transform } from "readable-stream";
import crc32 from "buffer-crc32";
import { collectStream } from "../utils.js";
/**
* JSON Format Plugin
*
* @module plugins/json
* @license [MIT]{@link https://github.com/archiverjs/node-archiver/blob/master/LICENSE}
* @copyright (c) 2012-2014 Chris Talkington, contributors.
*/
export default class Json extends Transform {
/**
* @constructor
* @param {(JsonOptions|TransformOptions)} options
*/
constructor(options) {
super({ ...options });
this.files = [];
}
/**
* [_transform description]
*
* @private
* @param {Buffer} chunk
* @param {String} encoding
* @param {Function} callback
* @return void
*/
_transform(chunk, encoding, callback) {
callback(null, chunk);
}
/**
* [_writeStringified description]
*
* @private
* @return void
*/
_writeStringified() {
var fileString = JSON.stringify(this.files);
this.write(fileString);
}
/**
* [append description]
*
* @param {(Buffer|Stream)} source
* @param {EntryData} data
* @param {Function} callback
* @return void
*/
append(source, data, callback) {
var self = this;
data.crc32 = 0;
function onend(err, sourceBuffer) {
if (err) {
callback(err);
return;
}
data.size = sourceBuffer.length || 0;
data.crc32 = crc32.unsigned(sourceBuffer);
self.files.push(data);
callback(null, data);
}
if (data.sourceType === "buffer") {
onend(null, source);
} else if (data.sourceType === "stream") {
collectStream(source, onend);
}
}
/**
* [finalize description]
*
* @return void
*/
finalize() {
this._writeStringified();
this.end();
}
}
+118
View File
@@ -0,0 +1,118 @@
import zlib from "zlib";
import engine from "tar-stream";
import { collectStream } from "../utils.js";
/**
* TAR Format Plugin
*
* @module plugins/tar
* @license [MIT]{@link https://github.com/archiverjs/node-archiver/blob/master/LICENSE}
* @copyright (c) 2012-2014 Chris Talkington, contributors.
*/
export default class Tar {
/**
* @constructor
* @param {TarOptions} options
*/
constructor(options) {
options = this.options = {
gzip: false,
...options,
};
if (typeof options.gzipOptions !== "object") {
options.gzipOptions = {};
}
this.engine = engine.pack(options);
this.compressor = false;
if (options.gzip) {
this.compressor = zlib.createGzip(options.gzipOptions);
this.compressor.on("error", this._onCompressorError.bind(this));
}
}
/**
* [_onCompressorError description]
*
* @private
* @param {Error} err
* @return void
*/
_onCompressorError(err) {
this.engine.emit("error", err);
}
/**
* [append description]
*
* @param {(Buffer|Stream)} source
* @param {TarEntryData} data
* @param {Function} callback
* @return void
*/
append(source, data, callback) {
var self = this;
data.mtime = data.date;
function append(err, sourceBuffer) {
if (err) {
callback(err);
return;
}
self.engine.entry(data, sourceBuffer, function (err) {
callback(err, data);
});
}
if (data.sourceType === "buffer") {
append(null, source);
} else if (data.sourceType === "stream" && data.stats) {
data.size = data.stats.size;
var entry = self.engine.entry(data, function (err) {
callback(err, data);
});
source.pipe(entry);
} else if (data.sourceType === "stream") {
collectStream(source, append);
}
}
/**
* [finalize description]
*
* @return void
*/
finalize() {
this.engine.finalize();
}
/**
* [on description]
*
* @return this.engine
*/
on() {
return this.engine.on.apply(this.engine, arguments);
}
/**
* [pipe description]
*
* @param {String} destination
* @param {Object} options
* @return this.engine
*/
pipe(destination, options) {
if (this.compressor) {
return this.engine.pipe
.apply(this.engine, [this.compressor])
.pipe(destination, options);
} else {
return this.engine.pipe.apply(this.engine, arguments);
}
}
/**
* [unpipe description]
*
* @return this.engine
*/
unpipe() {
if (this.compressor) {
return this.compressor.unpipe.apply(this.compressor, arguments);
} else {
return this.engine.unpipe.apply(this.engine, arguments);
}
}
}
+72
View File
@@ -0,0 +1,72 @@
import engine from "zip-stream";
/**
* 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.
*/
export default class Zip {
/**
* @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}
*/
constructor(options) {
options = this.options = {
comment: "",
forceUTC: false,
namePrependSlash: false,
store: false,
...options,
};
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
*/
append(source, data, callback) {
this.engine.entry(source, data, callback);
}
/**
* @return void
*/
finalize() {
this.engine.finalize();
}
/**
* @return this.engine
*/
on() {
return this.engine.on.apply(this.engine, arguments);
}
/**
* @return this.engine
*/
pipe() {
return this.engine.pipe.apply(this.engine, arguments);
}
/**
* @return this.engine
*/
unpipe() {
return this.engine.unpipe.apply(this.engine, arguments);
}
}