How to use the sax.MAX_BUFFER_LENGTH function in sax

To help you get started, we’ve selected a few sax examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github danmactough / node-feedparser / lib / feedparser / index.js View on Github external
TransformStream.call(this);
  this._readableState.objectMode = true;
  this._readableState.highWaterMark = 16; // max. # of output nodes buffered

  this.init();

  // Parse options
  this.options = _.assign({}, options);
  if (!('strict' in this.options)) this.options.strict = false;
  if (!('normalize' in this.options)) this.options.normalize = true;
  if (!('addmeta' in this.options)) this.options.addmeta = true;
  if (!('resume_saxerror' in this.options)) this.options.resume_saxerror = true;
  if ('MAX_BUFFER_LENGTH' in this.options) {
    sax.MAX_BUFFER_LENGTH = this.options.MAX_BUFFER_LENGTH; // set to Infinity to have unlimited buffers
  } else {
    sax.MAX_BUFFER_LENGTH = 16 * 1024 * 1024; // 16M versus the 64K default
  }
  if (this.options.feedurl) this.xmlbase.unshift({ '#name': 'xml', '#': this.options.feedurl});

  // See https://github.com/isaacs/sax-js for more info
  this.stream = sax.createStream(this.options.strict /* strict mode - no by default */, {lowercase: true, xmlns: true });
  this.stream.on('error', this.handleSaxError.bind(this));
  this.stream.on('processinginstruction', this.handleProcessingInstruction.bind(this));
  this.stream.on('opentag', this.handleOpenTag.bind(this));
  this.stream.on('closetag',this.handleCloseTag.bind(this));
  this.stream.on('text', this.handleText.bind(this));
  this.stream.on('cdata', this.handleText.bind(this));
  this.stream.on('end', this.handleEnd.bind(this));
}
util.inherits(FeedParser, TransformStream);
github JpEncausse / WSRNodeJS / script / vendor / feedparser.js View on Github external
FeedParser.prototype.parseOpts = function (options) {
  this.options = options || {};
  if (!('strict' in this.options)) this.options.strict = false;
  if (!('normalize' in this.options)) this.options.normalize = true;
  if (!('addmeta' in this.options)) this.options.addmeta = true;
  if (!('resume_saxerror' in this.options)) this.options.resume_saxerror = true;
  if ('MAX_BUFFER_LENGTH' in this.options) {
    sax.MAX_BUFFER_LENGTH = this.options.MAX_BUFFER_LENGTH; // set to Infinity to have unlimited buffers
  } else {
    sax.MAX_BUFFER_LENGTH = 16 * 1024 * 1024; // 16M versus the 64K default
  }
  if (this.options.feedurl) this.xmlbase.unshift({ '#name': 'xml', '#': this.options.feedurl});
};
github danmactough / node-opmlparser / main.js View on Github external
OpmlParser.prototype.parseOpts = function (options) {
  this.options = options || {};
  if (!('strict' in this.options)) this.options.strict = false;
  if (!('resume_saxerror' in this.options)) this.options.resume_saxerror = true;
  if ('MAX_BUFFER_LENGTH' in this.options) {
    sax.MAX_BUFFER_LENGTH = this.options.MAX_BUFFER_LENGTH; // set to Infinity to have unlimited buffers
  } else {
    sax.MAX_BUFFER_LENGTH = 16 * 1024 * 1024; // 16M versus the 64K default
  }
  if (this.options.opmlurl) this.xmlbase.unshift({ '#name': 'xml', '#': this.options.opmlurl});
};
github vpdb / server / src / modules / sax-async.js View on Github external
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

'use strict';

var fs  = require('fs');
var sax  = require('sax');
var util  = require('util');
var events = require('events');

sax.MAX_BUFFER_LENGTH = 64 * 1024 * 1024;

/**
 * A wrapper for sax-js that supports pausing and resuming streams.
 *
 * When pausing, the file reader is paused as well. However, since sax-js will
 * continue parsing the current chunk, we buffer subsequent events and emit
 * them when {@link #resume()} is called.
 *
 * @param filename
 * @constructor
 */
function Parser(filename) {
	events.EventEmitter.call(this);
	this.filename = filename;
	this.stack = [];
	this.paused = false;
github sikuli / sieveable / lib / index / tag-name-extractor.js View on Github external
const sax = require('sax'),
  fs = require('fs'),
  path = require('path'),
  Promise = require('bluebird'),
  log = require('../logger'),
  _ = require('lodash'),
  strict = true;
sax.MAX_BUFFER_LENGTH = 128 * 1024;

function FileExtractingError(message, fileName) {
  this.message = message;
  this.fileName = fileName;
  this.name = 'FileExtractingError';
}
FileExtractingError.prototype = Object.create(Error.prototype);
FileExtractingError.prototype.constructor = FileExtractingError;

module.exports = function extractTagName(xmlFileNames, targetDir, postfix) {
  log.info('Extracting node tags and attributes for %d files to %s',
    xmlFileNames.length, targetDir);
  return Promise.map(xmlFileNames, (xmlFile) => {
    const outFile = path.resolve(targetDir,
        `${path.basename(xmlFile, '.xml')}${postfix}.txt`),
      readStream = fs.createReadStream(xmlFile, {

sax

An evented streaming XML parser in JavaScript

ISC
Latest version published 6 months ago

Package Health Score

78 / 100
Full package analysis