@signalk/nmea0183-signalk
Version:
A node.js/javascript parser for NMEA0183 sentences. Sentences are parsed to Signal K format.
43 lines • 1.52 kB
JavaScript
;
/**
* Legacy streaming compatibility wrapper.
*
* Kept for historical reasons; the original implementation relied on a
* `.stream()` method on the Parser class that has since been removed, so in
* practice this shim does not produce events today. It is preserved as an
* entry point in case a streaming wrapper is reintroduced, and to keep the
* file/export surface stable across the TypeScript migration.
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const stream_1 = require("stream");
const _1 = __importDefault(require("./"));
class CompatParser extends stream_1.Transform {
parser;
constructor(opts = {}) {
const streamOpts = {
...(opts.stream ?? {}),
objectMode: true
};
super(streamOpts);
this.parser = new _1.default(opts);
}
_transform(chunk, _encoding, done) {
try {
const data = typeof chunk === 'string' ? chunk : chunk.toString('utf8');
const delta = this.parser.parse(data.trim());
if (delta !== null) {
this.emit('delta', delta);
this.push(delta);
}
done();
}
catch (err) {
done(err instanceof Error ? err : new Error(String(err)));
}
}
}
exports.default = CompatParser;
//# sourceMappingURL=CompatParser.js.map