Files
NapCatQQ/.pnpm-store/v3/files/57/b7533f65dcd601c459c8f8ba97ba51676f506ac44110e8425409643428b3a9cfd206fc5811e42f61d6062dfdb6b0edb9a58ea6e3c8e03cbfc4bc4904c6405d
T
TanTan e311ca3275
Build NapCat Artifacts / Type Check & Test (push) Waiting to run
docs: 仓库链接指向本镜像仓库
2026-11-13 09:25:58 +08:00

50 lines
1.2 KiB
Plaintext

'use strict';
const tar = require('../tar');
const gzip = require('../gzip');
const utils = require('../utils');
const stream = require('stream');
const pump = require('pump');
const ready = require('get-ready');
class TgzFileStream extends stream.Transform {
constructor(opts) {
opts = opts || {};
super(opts);
const sourceType = this._sourceType = utils.sourceType(opts.source);
const tarStream = this._tarStream = new tar.FileStream(opts);
opts = utils.clone(opts);
delete opts.source;
const gzipStream = new gzip.FileStream(opts);
gzipStream.on('data', chunk => {
this.push(chunk);
});
gzipStream.on('end', () => this.ready(true));
pump(tarStream, gzipStream, err => {
err && this.emit('error', err);
});
if (sourceType !== 'stream' && sourceType !== undefined) {
this.end();
}
}
_transform(chunk, encoding, callback) {
this._tarStream.write(chunk, encoding, callback);
}
_flush(callback) {
if (this._sourceType === 'stream' || this._sourceType === undefined) {
this._tarStream.end();
}
this.ready(callback);
}
}
ready.mixin(TgzFileStream.prototype);
module.exports = TgzFileStream;