Comparing version 3.0.1 to 3.0.2
108
lib/index.js
@@ -113,87 +113,79 @@ 'use strict'; | ||
exports.Stream = internals.Stream = function (needle) { | ||
exports.Stream = internals.Stream = class extends Stream.Writable { | ||
const self = this; | ||
constructor(needle) { | ||
Stream.Writable.call(this); | ||
super(); | ||
this.needle(needle); | ||
this._haystack = new Vise(); | ||
this._indexOf = this._needle.length > 2 ? exports.horspool : internals._indexOf; | ||
this.needle(needle); | ||
this._haystack = new Vise(); | ||
this._indexOf = this._needle.length > 2 ? exports.horspool : internals._indexOf; | ||
this.on('finish', () => { | ||
this.on('finish', () => { | ||
// Flush out the remainder | ||
// Flush out the remainder | ||
const chunks = self._haystack.chunks(); | ||
for (let i = 0; i < chunks.length; ++i) { | ||
self.emit('haystack', chunks[i]); | ||
} | ||
const chunks = this._haystack.chunks(); | ||
for (let i = 0; i < chunks.length; ++i) { | ||
this.emit('haystack', chunks[i]); | ||
} | ||
setImmediate(() => { // Give pending events a chance to fire | ||
self.emit('close'); | ||
setImmediate(() => this.emit('close')); // Give pending events a chance to fire | ||
}); | ||
}); | ||
}; | ||
} | ||
Hoek.inherits(internals.Stream, Stream.Writable); | ||
needle(needle) { | ||
this._needle = exports.compile(needle); | ||
} | ||
internals.Stream.prototype.needle = function (needle) { | ||
_write(chunk, encoding, next) { | ||
this._needle = exports.compile(needle); | ||
}; | ||
this._haystack.push(chunk); | ||
let match = this._indexOf(this._haystack, this._needle); | ||
if (match === -1 && | ||
chunk.length >= this._needle.length) { | ||
internals.Stream.prototype._write = function (chunk, encoding, next) { | ||
this._flush(this._haystack.length - chunk.length); | ||
} | ||
this._haystack.push(chunk); | ||
while (match !== -1) { | ||
this._flush(match); | ||
this._haystack.shift(this._needle.length); | ||
this.emit('needle'); | ||
let match = this._indexOf(this._haystack, this._needle); | ||
if (match === -1 && | ||
chunk.length >= this._needle.length) { | ||
match = this._indexOf(this._haystack, this._needle); | ||
} | ||
this._flush(this._haystack.length - chunk.length); | ||
} | ||
if (this._haystack.length) { | ||
const notChecked = this._haystack.length - this._needle.length + 1; // Not enough space for Horspool | ||
let i = notChecked; | ||
for (; i < this._haystack.length; ++i) { | ||
if (this._haystack.startsWith(this._needle.value, i, this._haystack.length - i)) { | ||
break; | ||
} | ||
} | ||
while (match !== -1) { | ||
this._flush(match); | ||
this._haystack.shift(this._needle.length); | ||
this.emit('needle'); | ||
match = this._indexOf(this._haystack, this._needle); | ||
} | ||
if (this._haystack.length) { | ||
const notChecked = this._haystack.length - this._needle.length + 1; // Not enough space for Horspool | ||
let i = notChecked; | ||
for (; i < this._haystack.length; ++i) { | ||
if (this._haystack.startsWith(this._needle.value, i, this._haystack.length - i)) { | ||
break; | ||
} | ||
this._flush(i); | ||
} | ||
this._flush(i); | ||
return next(); | ||
} | ||
return next(); | ||
}; | ||
_flush(pos) { | ||
internals.Stream.prototype._flush = function (pos) { | ||
const chunks = this._haystack.shift(pos); | ||
for (let i = 0; i < chunks.length; ++i) { | ||
this.emit('haystack', chunks[i]); | ||
const chunks = this._haystack.shift(pos); | ||
for (let i = 0; i < chunks.length; ++i) { | ||
this.emit('haystack', chunks[i]); | ||
} | ||
} | ||
}; | ||
flush() { | ||
internals.Stream.prototype.flush = function () { | ||
const chunks = this._haystack.shift(this._haystack.length); | ||
for (let i = 0; i < chunks.length; ++i) { | ||
this.emit('haystack', chunks[i]); | ||
const chunks = this._haystack.shift(this._haystack.length); | ||
for (let i = 0; i < chunks.length; ++i) { | ||
this.emit('haystack', chunks[i]); | ||
} | ||
} | ||
}; |
{ | ||
"name": "nigel", | ||
"description": "BoyerMooreHorspool algorithms", | ||
"version": "3.0.1", | ||
"version": "3.0.2", | ||
"repository": "git://github.com/hapijs/nigel", | ||
@@ -15,3 +15,3 @@ "main": "lib/index.js", | ||
"engines": { | ||
"node": ">=8.9.0" | ||
"node": ">=8.12.0" | ||
}, | ||
@@ -24,3 +24,3 @@ "dependencies": { | ||
"code": "5.x.x", | ||
"lab": "15.x.x", | ||
"lab": "17.x.x", | ||
"teamwork": "3.x.x" | ||
@@ -27,0 +27,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
7226
129