@salesforce/core
Version:
Core libraries to interact with SFDX projects, orgs, and APIs.
66 lines • 2.59 kB
JavaScript
;
/*
* Copyright 2026, Salesforce, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ZipWriter = void 0;
const node_stream_1 = require("node:stream");
const jszip_1 = __importDefault(require("jszip"));
const logger_1 = require("../logger/logger");
const sfError_1 = require("../sfError");
class ZipWriter extends node_stream_1.Writable {
rootDestination;
zip = (0, jszip_1.default)();
zipBuffer;
logger;
constructor(rootDestination) {
super({ objectMode: true });
this.rootDestination = rootDestination;
const destination = rootDestination ? `for: ${rootDestination}` : 'in memory';
this.logger = logger_1.Logger.childFromRoot(this.constructor.name);
this.logger.debug(`generating zip ${destination}`);
}
get buffer() {
if (!this.zipBuffer) {
throw new sfError_1.SfError('Must finalize the ZipWriter before getting a buffer');
}
return this.zipBuffer;
}
async addToStore(contents, path) {
// Ensure only posix paths are added to zip files
const posixPath = path.replace(/\\/g, '/');
this.zip.file(posixPath, contents);
return Promise.resolve();
}
async finalize() {
// compression-/speed+ (0)<---(3)---------->(9) compression+/speed-
// 3 appears to be a decent balance of compression and speed. It felt like
// higher values = diminishing returns on compression and made conversion slower
this.zipBuffer = await this.zip.generateAsync({
type: 'nodebuffer',
compression: 'DEFLATE',
compressionOptions: { level: 3 },
});
this.logger.debug('Generated zip complete');
}
getDestinationPath() {
return this.rootDestination;
}
}
exports.ZipWriter = ZipWriter;
//# sourceMappingURL=zipWriter.js.map