Refactored code to match code-style

This commit is contained in:
2021-12-02 13:40:56 +01:00
parent 9095e21e6f
commit 56ac283544
11 changed files with 143 additions and 141 deletions

View File

@@ -1,5 +1,5 @@
const logger = require.main.require("./helper/logger.js")("RegexBlockStream");
const { Transform } = require('stream')
const { Transform } = require("stream");
/**
* Matches whole blocks as regex and passes them on
@@ -27,7 +27,7 @@ class RegexBlockStream extends Transform{
}
_transform(chunk, encoding, next){
chunk = this.readableBuffer.length? this.readableBuffer.join('') + chunk: chunk; // Add previous buffer to current chunk
chunk = this.readableBuffer.length? this.readableBuffer.join("") + chunk: chunk; // Add previous buffer to current chunk
this.readableBuffer.length && this.readableBuffer.clear(); // Clear buffer once we read it
let matches = chunk.match(this.matcher); // Match
@@ -44,7 +44,7 @@ class RegexBlockStream extends Transform{
if(matches){
matches.forEach((match) => {
this.push(match); // Write match to stream
if(chunk) chunk = chunk.replace(match, ''); // Remove match from chunks
if(chunk) chunk = chunk.replace(match, ""); // Remove match from chunks
});
}
if(chunk) return chunk;
@@ -53,6 +53,7 @@ class RegexBlockStream extends Transform{
_flush(next){
if(matchAllOnFlush){ // When requested, we'll match one last time over the remaining buffer
let chunk = this.readableBuffer.join('');
let chunk = this.readableBuffer.join("");
let matches = chunk.match(this.matcher); // Match remaining buffer
_writeMatches(matches); // Write matches including last element
}