UNPKG

molstar

Version:

A comprehensive macromolecular library.

65 lines 2.51 kB
/** * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info. * * Taken/adapted from DensityServer (https://github.com/dsehnal/DensityServer) * * @author David Sehnal <david.sehnal@gmail.com> */ import { __awaiter, __generator } from "tslib"; import * as Schema from './binary-schema'; var _schema; (function (_schema) { var array = Schema.array, obj = Schema.obj, int = Schema.int, bool = Schema.bool, float = Schema.float, str = Schema.str; _schema.schema = obj([ ['formatVersion', str], ['axisOrder', array(int)], ['origin', array(float)], ['dimensions', array(float)], ['spacegroup', obj([ ['number', int], ['size', array(float)], ['angles', array(float)], ['isPeriodic', bool], ])], ['channels', array(str)], ['valueType', str], ['blockSize', int], ['sampling', array(obj([ ['byteOffset', float], ['rate', int], ['valuesInfo', array(obj([ ['mean', float], ['sigma', float], ['min', float], ['max', float] ]))], ['sampleCount', array(int)] ]))] ]); })(_schema || (_schema = {})); var headerSchema = _schema.schema; export function encodeHeader(header) { return Schema.encode(headerSchema, header); } export function readHeader(file) { return __awaiter(this, void 0, void 0, function () { var buffer, headerSize, header; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, file.readBuffer(0, 4 * 4096)]; case 1: buffer = (_a.sent()).buffer; headerSize = buffer.readInt32LE(0); if (!(headerSize > buffer.byteLength - 4)) return [3 /*break*/, 3]; return [4 /*yield*/, file.readBuffer(0, headerSize + 4)]; case 2: buffer = (_a.sent()).buffer; _a.label = 3; case 3: header = Schema.decode(headerSchema, buffer, 4); return [2 /*return*/, { header: header, dataOffset: headerSize + 4 }]; } }); }); } //# sourceMappingURL=data-format.js.map