UNPKG

@salesforce/core

Version:

Core libraries to interact with SFDX projects, orgs, and APIs.

54 lines 1.95 kB
"use strict"; /* * 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 */ Object.defineProperty(exports, "__esModule", { value: true }); exports.DirectoryWriter = void 0; const stream_1 = require("stream"); const fs = require("fs"); const os = require("os"); const path = require("path"); const util_1 = require("util"); const pipeline = (0, util_1.promisify)(stream_1.pipeline); class DirectoryWriter { 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 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