Comparing version 1.3.0 to 1.3.1
@@ -162,3 +162,3 @@ "use strict"; | ||
class SAXParser { | ||
constructor(events = 0, options = { highWaterMark: 64 * 1024 }) { | ||
constructor(events = 0, options = { highWaterMark: 32 * 1024 }) { | ||
this.eventTrap = (event, ptr, len) => { | ||
@@ -205,5 +205,13 @@ const uint8array = new Uint8Array(this.wasmSaxParser.memory.buffer.slice(ptr, ptr + len)); | ||
write(chunk, offset = 0) { | ||
const { write } = this.wasmSaxParser; | ||
if (!this.writeBuffer) { | ||
this.writeBuffer = new Uint8Array(this.wasmSaxParser.memory.buffer, 0, this.options.highWaterMark); | ||
const { write, memory: { buffer } } = this.wasmSaxParser; | ||
// Allocations within the WASM process | ||
// invalidate reference to the memory buffer. | ||
// We check for this and create a new Uint8Array | ||
// with the new memory buffer reference if needed. | ||
// **NOTE** These allocations can slow down parsing | ||
// if they become excessive. Consider adjusting the | ||
// highWaterMark in the options up or down to find the optimal | ||
// memory allocation to prevent too many new Uint8Array instances. | ||
if (!this.writeBuffer || this.writeBuffer.buffer !== buffer) { | ||
this.writeBuffer = new Uint8Array(buffer, 0, this.options.highWaterMark); | ||
} | ||
@@ -210,0 +218,0 @@ this.writeBuffer.set(chunk); |
{ | ||
"name": "sax-wasm", | ||
"version": "1.3.0", | ||
"version": "1.3.1", | ||
"repository": "https://github.com/justinwilaby/sax-wasm", | ||
@@ -5,0 +5,0 @@ "description": "An extremely fast JSX, HTML and XML parser written in Rust compiled to WebAssembly for Node and the Web", |
@@ -33,3 +33,3 @@ # SAX (Simple API for XML) for WebAssembly | ||
// Instantiate | ||
const options = {highWaterMark: 64 * 1024}; // 64k chunks | ||
const options = {highWaterMark: 32 * 1024}; // 32k chunks | ||
const parser = new SAXParser(SaxEventType.Attribute | SaxEventType.OpenTag, options); | ||
@@ -51,3 +51,3 @@ parser.eventHandler = (event, data) => { | ||
}); | ||
readable.on('end', parser.end); | ||
readable.on('end', () => parser.end()); | ||
} | ||
@@ -54,0 +54,0 @@ }); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
54829
345