@salesforce/core
Version:
Core libraries to interact with SFDX projects, orgs, and APIs.
78 lines • 3.09 kB
JavaScript
/*
* Copyright (c) 2021, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DirectoryWriter = void 0;
const node_stream_1 = require("node:stream");
const fs = __importStar(require("node:fs"));
const os = __importStar(require("node:os"));
const path = __importStar(require("node:path"));
const node_util_1 = require("node:util");
const pipeline = (0, node_util_1.promisify)(node_stream_1.pipeline);
class DirectoryWriter {
rootDestination;
constructor(rootDestination) {
this.rootDestination = rootDestination;
if (!this.rootDestination) {
this.rootDestination = fs.mkdtempSync(`${os.tmpdir()}${path.sep}`);
}
else {
fs.mkdirSync(this.rootDestination, { recursive: true });
}
}
// eslint-disable-next-line class-methods-use-this
get buffer() {
throw new Error('Not implemented');
}
async addToStore(contents, targetPath) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const destPath = path.join(this.rootDestination, targetPath);
fs.mkdirSync(path.dirname(destPath), { recursive: true });
if (contents instanceof node_stream_1.Readable) {
const writeStream = fs.createWriteStream(destPath);
await pipeline(contents, writeStream);
}
else if (typeof contents === 'string') {
fs.writeFileSync(destPath, contents);
}
else if (contents instanceof Buffer) {
fs.writeFileSync(destPath, contents);
}
}
// eslint-disable-next-line class-methods-use-this
finalize() {
return Promise.resolve(undefined);
}
getDestinationPath() {
return this.rootDestination;
}
}
exports.DirectoryWriter = DirectoryWriter;
//# sourceMappingURL=directoryWriter.js.map
;