@itwin/object-storage-tests-backend
Version:
Tests for generic storage packages
36 lines • 1.65 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.TestLocalFileManager = void 0;
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
const fs_1 = require("fs");
const path = require("path");
class TestLocalFileManager {
constructor(rootDir) {
this._downloadsDir = path.join(rootDir, "downloads");
this._uploadsDir = path.join(rootDir, "uploads");
}
async getDownloadsDir() {
if (!fs_1.existsSync(this._downloadsDir))
await fs_1.promises.mkdir(this._downloadsDir, { recursive: true });
return this._downloadsDir;
}
async createAndWriteFile(fileName, content) {
if (!fs_1.existsSync(this._uploadsDir))
await fs_1.promises.mkdir(this._uploadsDir, { recursive: true });
const filePath = path.join(this._uploadsDir, fileName);
await fs_1.promises.writeFile(filePath, content !== null && content !== void 0 ? content : "");
return filePath;
}
async purgeCreatedFiles() {
this.purgeDirectory(this._downloadsDir);
this.purgeDirectory(this._uploadsDir);
}
purgeDirectory(directory) {
fs_1.rmSync(directory, { recursive: true, force: true });
}
}
exports.TestLocalFileManager = TestLocalFileManager;
//# sourceMappingURL=TestLocalFileManager.js.map