UNPKG

node-djiparsetxt

Version:

command-line application that reads a DJI '.txt' file and outputs a json.

63 lines 2.78 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.SerializeRecordsCommand = void 0; var RecordTypes_1 = require("../services/RecordTypes"); var Command_1 = require("./Command"); var SerializeRecordsCommand = /** @class */ (function (_super) { __extends(SerializeRecordsCommand, _super); function SerializeRecordsCommand() { return _super !== null && _super.apply(this, arguments) || this; } SerializeRecordsCommand.prototype.exec = function (options) { var file = options.file; var recordsCache = options.records; if (file.buffer === null) { return Buffer.alloc(0); } var unscrambledBuf = Buffer.alloc(file.buffer.length); file.buffer.copy(unscrambledBuf, 0, 0, 100); var offset = 100; for (var _i = 0, _a = recordsCache.records; _i < _a.length; _i++) { var record = _a[_i]; unscrambledBuf.writeUInt8(record.type, offset++); unscrambledBuf.writeUInt8(record.length, offset++); // jpeg records don't have scrambling, treat accordingly if (record.type !== RecordTypes_1.RecordTypes.JPEG) { for (var _b = 0, _c = record.data; _b < _c.length; _b++) { var buff = _c[_b]; buff.copy(unscrambledBuf, offset); offset += buff.length; } unscrambledBuf.writeUInt8(0xff, offset++); } else { unscrambledBuf.writeUInt8(0, offset++); unscrambledBuf.writeUInt8(0, offset++); for (var _d = 0, _e = record.data; _d < _e.length; _d++) { var buf = _e[_d]; for (var ii = 0; ii < buf.length; ii++) { unscrambledBuf.writeUInt8(buf[ii], offset++); } } } } file.buffer.copy(unscrambledBuf, offset, offset); return unscrambledBuf; }; return SerializeRecordsCommand; }(Command_1.Command)); exports.SerializeRecordsCommand = SerializeRecordsCommand; //# sourceMappingURL=SerializeRecordsCommand.js.map