@shapediver/sdk.sdtf-v1
Version:
Official sdTF SDK for TypeScript
38 lines • 1.97 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());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.SdtfFileBufferCache = void 0;
const sdk_sdtf_core_1 = require("@shapediver/sdk.sdtf-core");
const SdtfFileUtils_1 = require("../utils/SdtfFileUtils");
const SdtfBinaryBufferCache_1 = require("./SdtfBinaryBufferCache");
class SdtfFileBufferCache extends SdtfBinaryBufferCache_1.SdtfBinaryBufferCache {
constructor(absolutePath) {
super();
this.fileUtils = new SdtfFileUtils_1.SdtfFileUtils();
const index = absolutePath.lastIndexOf('/');
this.basePath = absolutePath.substring(0, index);
}
acquireBuffer(relativePath, offset, length) {
return __awaiter(this, void 0, void 0, function* () {
let buffer;
try {
buffer = yield this.fileUtils.readFile(`${this.basePath}/${relativePath}`);
}
catch (e) {
throw new sdk_sdtf_core_1.SdtfError(`Cannot read buffer: ${e.message}`);
}
this.storeInCache(this.calcCacheKey(relativePath), this.cacheIdFullBuffer, new DataView(buffer));
return new DataView(buffer, offset, length);
});
}
}
exports.SdtfFileBufferCache = SdtfFileBufferCache;
//# sourceMappingURL=SdtfFileBufferCache.js.map