@canboat/canboatjs
Version:
Native javascript version of canboat
47 lines • 1.77 kB
JavaScript
/**
* Copyright 2018 Scott Bender (scott@scottbender.net)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.fromPgnStream = fromPgnStream;
const utilities_1 = require("./utilities");
const stream_1 = require("stream");
const fromPgn_1 = require("./fromPgn");
const util_1 = __importDefault(require("util"));
const debug = (0, utilities_1.createDebug)('canboatjs:FromPgnStream');
function fromPgnStream(options = {}) {
stream_1.Transform.call(this, {
objectMode: true
});
this.fromPgn = new fromPgn_1.Parser(options);
this.fromPgn.on('pgn', (pgn) => {
this.push(pgn);
});
this.fromPgn.on('warning', (pgn, warning) => {
debug(`[warning] ${pgn.pgn} ${warning}`);
});
this.fromPgn.on('error', (pgn, error) => {
debug(`[error] ${pgn.pgn} ${error}`);
});
}
util_1.default.inherits(fromPgnStream, stream_1.Transform);
fromPgnStream.prototype._transform = function (chunk, encoding, done) {
this.fromPgn.parse(chunk);
done();
};
//# sourceMappingURL=fromPgnStream.js.map
;