@wocker/core
Version:
Core of the Wocker
42 lines (41 loc) • 1.95 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.FileSystemManager = void 0;
const fs_1 = __importDefault(require("fs"));
const promises_1 = require("stream/promises");
const FileSystem_1 = require("./FileSystem");
class FileSystemManager {
constructor(source, destination, fs = fs_1.default) {
this.fs = fs;
this.source = new FileSystem_1.FileSystem(source, this.fs);
this.destination = new FileSystem_1.FileSystem(destination, this.fs);
}
exists(...parts) {
return this.destination.exists(...parts);
}
mkdir(path, options) {
this.destination.mkdir(path, options);
}
copy(path, options) {
fs_1.default.cpSync(this.source.path(path), this.destination.path(path), options);
}
copyFile(path) {
return __awaiter(this, void 0, void 0, function* () {
const readStream = this.source.createReadStream(path), writeStream = this.destination.createWriteStream(path);
yield (0, promises_1.pipeline)(readStream, writeStream);
});
}
}
exports.FileSystemManager = FileSystemManager;