UNPKG

@btfuse/filesystem

Version:

Filesystem plugin for the Fuse framework

95 lines (92 loc) 3.05 kB
"use strict"; /* Copyright 2023 Breautek 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. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.FuseFileObject = void 0; const FusePath_1 = require("./FusePath"); const FuseFileType_1 = require("./FuseFileType"); const FuseDirectory_1 = require("./FuseDirectory"); /** * An object representing any kind of filesystem object */ class FuseFileObject { constructor(fs, path, parent) { this.$fs = fs; this.$path = path; if (parent) { if (typeof parent === 'string') { this.$path = FusePath_1.FusePath.resolve(parent, this.$path); } else { this.$path = FusePath_1.FusePath.resolve(parent.getPath(), this.$path); } } } getParent() { if (this.getPath() === '/') { return null; } return this.getDirectory('..'); } getPath() { return this.$path; } get(path) { return new FuseFileObject(this.$fs, path, this); } getDirectory(path) { let obj = this.get(path); return new FuseDirectory_1.FuseDirectory(obj); } async getType() { return await this.$fs.getFileType(this); } async isDirectory() { let type = await this.getType(); return type === FuseFileType_1.FuseFileType.DIRECTORY; } async isFile() { let type = await this.getType(); return type === FuseFileType_1.FuseFileType.DIRECTORY; } async getSize() { return await this.$fs.getSize(this); } async mkdir(recursive) { return await this.$fs.mkdir(this, recursive); } async read() { return await this.$fs.read(this, -1, 0); } async readChunk(length, offset) { return await this.$fs.read(this, length, offset || 0); } async truncate(data) { return await this.$fs.truncate(this, data === undefined || data === null ? new ArrayBuffer(0) : data); } async append(data) { return await this.$fs.append(this, data === undefined || data === null ? new ArrayBuffer(0) : data); } async write(data, offset) { data = data === undefined || data === null ? new ArrayBuffer(0) : data; return await this.$fs.write(this, data, offset); } async remove(recursive) { await this.$fs.remove(this, recursive); } async exists() { return await this.$fs.exists(this); } } exports.FuseFileObject = FuseFileObject; //# sourceMappingURL=FuseFileObject.js.map