@shapediver/sdk.sdtf-v1
Version:
Official sdTF SDK for TypeScript
34 lines • 1.15 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SdtfFileUtils = void 0;
const sdk_sdtf_core_1 = require("@shapediver/sdk.sdtf-core");
const path = require('path');
const fs = require('fs');
class SdtfFileUtils {
toAbsolutePath(relativePath) {
try {
return path.resolve(relativePath);
}
catch (e) {
throw new sdk_sdtf_core_1.SdtfError(`Could not resolve path '${relativePath}': ${e.message}`);
}
}
readFile(absolutePath) {
if (!fs.existsSync(absolutePath)) {
throw new sdk_sdtf_core_1.SdtfError(`Cannot find file at location '${absolutePath}'.`);
}
return new Promise((resolve, reject) => {
fs.readFile(absolutePath, (error, buffer) => {
if (error) {
reject(error);
return;
}
const data = new Uint8Array(buffer.byteLength);
data.set(buffer);
resolve(data.buffer);
});
});
}
}
exports.SdtfFileUtils = SdtfFileUtils;
//# sourceMappingURL=SdtfFileUtils.js.map