multipasta
Advanced tools
Comparing version 0.1.16 to 0.1.17
@@ -14,3 +14,3 @@ "use strict"; | ||
const indexes = {}; | ||
for (let i = 0; i < needle.length; i++) { | ||
for (let i = 0; i < needleLength; i++) { | ||
const b = needle[i]; | ||
@@ -36,12 +36,2 @@ if (indexes[b] === undefined) indexes[b] = []; | ||
} | ||
function emitMatch(state, chunk, startPos, callback) { | ||
if (state.previousChunk !== undefined) { | ||
callback(state.matchIndex, state.previousChunk); | ||
state.previousChunk = undefined; | ||
} | ||
if (startPos > 0) { | ||
callback(state.matchIndex, chunk.subarray(0, startPos)); | ||
} | ||
state.matchIndex += 1; | ||
} | ||
function make(needle, callback, seed) { | ||
@@ -53,20 +43,18 @@ const state = makeState(needle); | ||
} | ||
function write(chunk) { | ||
function writeUint8Array(chunk) { | ||
if (state.previousChunk !== undefined) { | ||
const newChunk = new Uint8Array(state.previousChunkLength + chunk.length); | ||
newChunk.set(state.previousChunk); | ||
newChunk.set(chunk, state.previousChunkLength); | ||
chunk = newChunk; | ||
state.previousChunk = undefined; | ||
state.previousChunkLength = 0; | ||
} | ||
let chunkLength = chunk.length; | ||
if (chunkLength < state.needleLength) { | ||
if (state.previousChunk === undefined) { | ||
state.previousChunk = chunk; | ||
state.previousChunkLength = chunkLength; | ||
return; | ||
} | ||
if (state.previousChunkLength + chunkLength < state.needleLength) { | ||
const newChunk = new Uint8Array(state.previousChunkLength + chunkLength); | ||
newChunk.set(state.previousChunk); | ||
newChunk.set(chunk, state.previousChunkLength); | ||
state.previousChunk = newChunk; | ||
state.previousChunkLength = newChunk.length; | ||
return; | ||
} | ||
state.previousChunk = chunk; | ||
state.previousChunkLength = chunkLength; | ||
return; | ||
} | ||
outer: for (let i = 0; i < chunkLength; i += state.needleLength) { | ||
outer: for (let i = state.needleLength - 1; i < chunkLength; i += state.needleLength) { | ||
if (chunk[i] in state.indexes === false) { | ||
@@ -78,28 +66,16 @@ continue; | ||
const startPosition = i - indexes[j]; | ||
if (startPosition + state.needleLength > chunkLength) { | ||
if (startPosition < 0) { | ||
continue; | ||
} | ||
if (startPosition < 0) { | ||
if (state.previousChunk === undefined) { | ||
continue; | ||
} else if (state.previousChunk[state.previousChunkLength + startPosition] === state.firstByte) { | ||
const newChunk = new Uint8Array(state.previousChunkLength + chunkLength); | ||
newChunk.set(state.previousChunk); | ||
newChunk.set(chunk, state.previousChunkLength); | ||
chunk = newChunk; | ||
state.previousChunk = undefined; | ||
chunkLength = newChunk.length; | ||
i += state.previousChunkLength; | ||
const newStartPosition = state.previousChunkLength + startPosition; | ||
if (state.exactMatch(chunk, newStartPosition)) { | ||
state.previousChunk = undefined; | ||
emitMatch(state, chunk, newStartPosition, callback); | ||
chunk = chunk.subarray(newStartPosition + state.needleLength); | ||
chunkLength = chunk.length; | ||
i = -1; | ||
continue outer; | ||
} | ||
} else if (startPosition + state.needleLength > chunkLength) { | ||
if (chunk[startPosition] === state.firstByte && chunk[chunkLength - 1] === state.needle[chunkLength - startPosition - 1]) { | ||
callback(state.matchIndex, chunk.subarray(0, startPosition)); | ||
state.previousChunk = chunk.subarray(startPosition); | ||
state.previousChunkLength = chunkLength - startPosition; | ||
return; | ||
} | ||
} else if (chunk[startPosition] === state.firstByte && chunk[startPosition + state.needleFirstVariationIndex] === state.needleFirstVariation && state.exactMatch(chunk, startPosition)) { | ||
emitMatch(state, chunk, startPosition, callback); | ||
if (startPosition > 0) { | ||
callback(state.matchIndex, chunk.subarray(0, startPosition)); | ||
} | ||
state.matchIndex += 1; | ||
chunk = chunk.subarray(startPosition + state.needleLength); | ||
@@ -112,12 +88,24 @@ chunkLength = chunkLength - startPosition - state.needleLength; | ||
} | ||
if (state.previousChunk !== undefined) { | ||
callback(state.matchIndex, state.previousChunk); | ||
state.previousChunk = chunk; | ||
state.previousChunkLength = chunkLength; | ||
} else if (chunkLength > 0) { | ||
state.previousChunk = chunk; | ||
state.previousChunkLength = chunkLength; | ||
} else { | ||
state.previousChunk = undefined; | ||
state.previousChunkLength = 0; | ||
if (chunkLength > 0) { | ||
if (chunk[chunkLength - 1] in state.indexes) { | ||
const indexes = state.indexes[chunk[chunkLength - 1]]; | ||
let earliestIndex = -1; | ||
for (let i = 0, len = indexes.length; i < len; i++) { | ||
const index = indexes[i]; | ||
if (chunk[chunkLength - 1 - index] === state.firstByte && i > earliestIndex) { | ||
earliestIndex = index; | ||
} | ||
} | ||
if (earliestIndex === -1) { | ||
callback(state.matchIndex, chunk); | ||
} else { | ||
if (chunkLength - 1 - earliestIndex > 0) { | ||
callback(state.matchIndex, chunk.subarray(0, chunkLength - 1 - earliestIndex)); | ||
} | ||
state.previousChunk = chunk.subarray(chunkLength - 1 - earliestIndex); | ||
state.previousChunkLength = earliestIndex + 1; | ||
} | ||
} else { | ||
callback(state.matchIndex, chunk); | ||
} | ||
} | ||
@@ -190,3 +178,3 @@ } | ||
return { | ||
write: "Buffer" in globalThis ? writeBuffer : write, | ||
write: "Buffer" in globalThis ? writeBuffer : writeUint8Array, | ||
end | ||
@@ -193,0 +181,0 @@ }; |
@@ -42,5 +42,5 @@ "use strict"; | ||
class MultipastaStream extends _nodeStream.Duplex { | ||
#parser; | ||
#canWrite = true; | ||
#writeCallback; | ||
_parser; | ||
_canWrite = true; | ||
_writeCallback; | ||
constructor(config) { | ||
@@ -50,3 +50,3 @@ super({ | ||
}); | ||
this.#parser = MP.make({ | ||
this._parser = MP.make({ | ||
...config, | ||
@@ -64,6 +64,10 @@ onField: (info, value) => { | ||
const file = new FileStream(info); | ||
file.on("resume", this._resume.bind(this)); | ||
this.push(file); | ||
this.emit("file", file); | ||
return chunk => { | ||
this.#canWrite = file.push(chunk); | ||
this._canWrite = file.push(chunk); | ||
if (chunk === null && !this._canWrite) { | ||
this._resume(); | ||
} | ||
}; | ||
@@ -78,26 +82,21 @@ }, | ||
}); | ||
this.on("drain", () => { | ||
this.#canWrite = true; | ||
if (this.#writeCallback !== undefined) { | ||
this.#writeCallback(); | ||
this.#writeCallback = undefined; | ||
} | ||
}); | ||
} | ||
_resume() { | ||
this._canWrite = true; | ||
if (this._writeCallback !== undefined) { | ||
this._writeCallback(); | ||
this._writeCallback = undefined; | ||
} | ||
} | ||
_read(_size) {} | ||
_write(chunk, encoding, callback) { | ||
const canWrite = this.#canWrite; | ||
if (chunk instanceof Uint8Array) { | ||
this.#parser.write(chunk); | ||
} else { | ||
this.#parser.write(Buffer.from(chunk, encoding)); | ||
} | ||
if (canWrite) { | ||
this._parser.write(chunk instanceof Uint8Array ? chunk : Buffer.from(chunk, encoding)); | ||
if (this._canWrite) { | ||
callback(); | ||
} else { | ||
this.#writeCallback = callback; | ||
this._writeCallback = callback; | ||
} | ||
} | ||
_final(callback) { | ||
this.#parser.end(); | ||
this._parser.end(); | ||
callback(); | ||
@@ -104,0 +103,0 @@ } |
@@ -36,4 +36,7 @@ /// <reference types="node" resolution-mode="require"/> | ||
export declare class MultipastaStream extends Duplex { | ||
#private; | ||
private _parser; | ||
private _canWrite; | ||
private _writeCallback; | ||
constructor(config: NodeConfig); | ||
_resume(): void; | ||
_read(_size: number): void; | ||
@@ -40,0 +43,0 @@ _write(chunk: any, encoding: BufferEncoding, callback: (error?: Error | null | undefined) => void): void; |
@@ -8,3 +8,3 @@ function noopMatch(_, __) { | ||
const indexes = {}; | ||
for (let i = 0; i < needle.length; i++) { | ||
for (let i = 0; i < needleLength; i++) { | ||
const b = needle[i]; | ||
@@ -30,12 +30,2 @@ if (indexes[b] === undefined) indexes[b] = []; | ||
} | ||
function emitMatch(state, chunk, startPos, callback) { | ||
if (state.previousChunk !== undefined) { | ||
callback(state.matchIndex, state.previousChunk); | ||
state.previousChunk = undefined; | ||
} | ||
if (startPos > 0) { | ||
callback(state.matchIndex, chunk.subarray(0, startPos)); | ||
} | ||
state.matchIndex += 1; | ||
} | ||
export function make(needle, callback, seed) { | ||
@@ -47,20 +37,18 @@ const state = makeState(needle); | ||
} | ||
function write(chunk) { | ||
function writeUint8Array(chunk) { | ||
if (state.previousChunk !== undefined) { | ||
const newChunk = new Uint8Array(state.previousChunkLength + chunk.length); | ||
newChunk.set(state.previousChunk); | ||
newChunk.set(chunk, state.previousChunkLength); | ||
chunk = newChunk; | ||
state.previousChunk = undefined; | ||
state.previousChunkLength = 0; | ||
} | ||
let chunkLength = chunk.length; | ||
if (chunkLength < state.needleLength) { | ||
if (state.previousChunk === undefined) { | ||
state.previousChunk = chunk; | ||
state.previousChunkLength = chunkLength; | ||
return; | ||
} | ||
if (state.previousChunkLength + chunkLength < state.needleLength) { | ||
const newChunk = new Uint8Array(state.previousChunkLength + chunkLength); | ||
newChunk.set(state.previousChunk); | ||
newChunk.set(chunk, state.previousChunkLength); | ||
state.previousChunk = newChunk; | ||
state.previousChunkLength = newChunk.length; | ||
return; | ||
} | ||
state.previousChunk = chunk; | ||
state.previousChunkLength = chunkLength; | ||
return; | ||
} | ||
outer: for (let i = 0; i < chunkLength; i += state.needleLength) { | ||
outer: for (let i = state.needleLength - 1; i < chunkLength; i += state.needleLength) { | ||
if (chunk[i] in state.indexes === false) { | ||
@@ -72,28 +60,16 @@ continue; | ||
const startPosition = i - indexes[j]; | ||
if (startPosition + state.needleLength > chunkLength) { | ||
if (startPosition < 0) { | ||
continue; | ||
} | ||
if (startPosition < 0) { | ||
if (state.previousChunk === undefined) { | ||
continue; | ||
} else if (state.previousChunk[state.previousChunkLength + startPosition] === state.firstByte) { | ||
const newChunk = new Uint8Array(state.previousChunkLength + chunkLength); | ||
newChunk.set(state.previousChunk); | ||
newChunk.set(chunk, state.previousChunkLength); | ||
chunk = newChunk; | ||
state.previousChunk = undefined; | ||
chunkLength = newChunk.length; | ||
i += state.previousChunkLength; | ||
const newStartPosition = state.previousChunkLength + startPosition; | ||
if (state.exactMatch(chunk, newStartPosition)) { | ||
state.previousChunk = undefined; | ||
emitMatch(state, chunk, newStartPosition, callback); | ||
chunk = chunk.subarray(newStartPosition + state.needleLength); | ||
chunkLength = chunk.length; | ||
i = -1; | ||
continue outer; | ||
} | ||
} else if (startPosition + state.needleLength > chunkLength) { | ||
if (chunk[startPosition] === state.firstByte && chunk[chunkLength - 1] === state.needle[chunkLength - startPosition - 1]) { | ||
callback(state.matchIndex, chunk.subarray(0, startPosition)); | ||
state.previousChunk = chunk.subarray(startPosition); | ||
state.previousChunkLength = chunkLength - startPosition; | ||
return; | ||
} | ||
} else if (chunk[startPosition] === state.firstByte && chunk[startPosition + state.needleFirstVariationIndex] === state.needleFirstVariation && state.exactMatch(chunk, startPosition)) { | ||
emitMatch(state, chunk, startPosition, callback); | ||
if (startPosition > 0) { | ||
callback(state.matchIndex, chunk.subarray(0, startPosition)); | ||
} | ||
state.matchIndex += 1; | ||
chunk = chunk.subarray(startPosition + state.needleLength); | ||
@@ -106,12 +82,24 @@ chunkLength = chunkLength - startPosition - state.needleLength; | ||
} | ||
if (state.previousChunk !== undefined) { | ||
callback(state.matchIndex, state.previousChunk); | ||
state.previousChunk = chunk; | ||
state.previousChunkLength = chunkLength; | ||
} else if (chunkLength > 0) { | ||
state.previousChunk = chunk; | ||
state.previousChunkLength = chunkLength; | ||
} else { | ||
state.previousChunk = undefined; | ||
state.previousChunkLength = 0; | ||
if (chunkLength > 0) { | ||
if (chunk[chunkLength - 1] in state.indexes) { | ||
const indexes = state.indexes[chunk[chunkLength - 1]]; | ||
let earliestIndex = -1; | ||
for (let i = 0, len = indexes.length; i < len; i++) { | ||
const index = indexes[i]; | ||
if (chunk[chunkLength - 1 - index] === state.firstByte && i > earliestIndex) { | ||
earliestIndex = index; | ||
} | ||
} | ||
if (earliestIndex === -1) { | ||
callback(state.matchIndex, chunk); | ||
} else { | ||
if (chunkLength - 1 - earliestIndex > 0) { | ||
callback(state.matchIndex, chunk.subarray(0, chunkLength - 1 - earliestIndex)); | ||
} | ||
state.previousChunk = chunk.subarray(chunkLength - 1 - earliestIndex); | ||
state.previousChunkLength = earliestIndex + 1; | ||
} | ||
} else { | ||
callback(state.matchIndex, chunk); | ||
} | ||
} | ||
@@ -184,3 +172,3 @@ } | ||
return { | ||
write: "Buffer" in globalThis ? writeBuffer : write, | ||
write: "Buffer" in globalThis ? writeBuffer : writeUint8Array, | ||
end | ||
@@ -187,0 +175,0 @@ }; |
@@ -5,5 +5,5 @@ import * as MP from "./index.js"; | ||
export class MultipastaStream extends Duplex { | ||
#parser; | ||
#canWrite = true; | ||
#writeCallback; | ||
_parser; | ||
_canWrite = true; | ||
_writeCallback; | ||
constructor(config) { | ||
@@ -13,3 +13,3 @@ super({ | ||
}); | ||
this.#parser = MP.make({ | ||
this._parser = MP.make({ | ||
...config, | ||
@@ -27,6 +27,10 @@ onField: (info, value) => { | ||
const file = new FileStream(info); | ||
file.on("resume", this._resume.bind(this)); | ||
this.push(file); | ||
this.emit("file", file); | ||
return chunk => { | ||
this.#canWrite = file.push(chunk); | ||
this._canWrite = file.push(chunk); | ||
if (chunk === null && !this._canWrite) { | ||
this._resume(); | ||
} | ||
}; | ||
@@ -41,26 +45,21 @@ }, | ||
}); | ||
this.on("drain", () => { | ||
this.#canWrite = true; | ||
if (this.#writeCallback !== undefined) { | ||
this.#writeCallback(); | ||
this.#writeCallback = undefined; | ||
} | ||
}); | ||
} | ||
_resume() { | ||
this._canWrite = true; | ||
if (this._writeCallback !== undefined) { | ||
this._writeCallback(); | ||
this._writeCallback = undefined; | ||
} | ||
} | ||
_read(_size) {} | ||
_write(chunk, encoding, callback) { | ||
const canWrite = this.#canWrite; | ||
if (chunk instanceof Uint8Array) { | ||
this.#parser.write(chunk); | ||
} else { | ||
this.#parser.write(Buffer.from(chunk, encoding)); | ||
} | ||
if (canWrite) { | ||
this._parser.write(chunk instanceof Uint8Array ? chunk : Buffer.from(chunk, encoding)); | ||
if (this._canWrite) { | ||
callback(); | ||
} else { | ||
this.#writeCallback = callback; | ||
this._writeCallback = callback; | ||
} | ||
} | ||
_final(callback) { | ||
this.#parser.end(); | ||
this._parser.end(); | ||
callback(); | ||
@@ -67,0 +66,0 @@ } |
{ | ||
"name": "multipasta", | ||
"version": "0.1.16", | ||
"version": "0.1.17", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -24,3 +24,3 @@ interface SearchState { | ||
const indexes: Record<number, number[]> = {} | ||
for (let i = 0; i < needle.length; i++) { | ||
for (let i = 0; i < needleLength; i++) { | ||
const b = needle[i] | ||
@@ -61,20 +61,2 @@ if (indexes[b] === undefined) indexes[b] = [] | ||
function emitMatch( | ||
state: SearchState, | ||
chunk: Uint8Array, | ||
startPos: number, | ||
callback: (index: number, chunk: Uint8Array) => void, | ||
) { | ||
if (state.previousChunk !== undefined) { | ||
callback(state.matchIndex, state.previousChunk) | ||
state.previousChunk = undefined | ||
} | ||
if (startPos > 0) { | ||
callback(state.matchIndex, chunk.subarray(0, startPos)) | ||
} | ||
state.matchIndex += 1 | ||
} | ||
export function make( | ||
@@ -91,22 +73,24 @@ needle: string, | ||
function write(chunk: Uint8Array): void { | ||
function writeUint8Array(chunk: Uint8Array): void { | ||
if (state.previousChunk !== undefined) { | ||
const newChunk = new Uint8Array(state.previousChunkLength + chunk.length) | ||
newChunk.set(state.previousChunk) | ||
newChunk.set(chunk, state.previousChunkLength) | ||
chunk = newChunk | ||
state.previousChunk = undefined | ||
state.previousChunkLength = 0 | ||
} | ||
let chunkLength = chunk.length | ||
if (chunkLength < state.needleLength) { | ||
if (state.previousChunk === undefined) { | ||
state.previousChunk = chunk | ||
state.previousChunkLength = chunkLength | ||
return | ||
} | ||
if (state.previousChunkLength + chunkLength < state.needleLength) { | ||
const newChunk = new Uint8Array(state.previousChunkLength + chunkLength) | ||
newChunk.set(state.previousChunk) | ||
newChunk.set(chunk, state.previousChunkLength) | ||
state.previousChunk = newChunk | ||
state.previousChunkLength = newChunk.length | ||
return | ||
} | ||
state.previousChunk = chunk | ||
state.previousChunkLength = chunkLength | ||
return | ||
} | ||
outer: for (let i = 0; i < chunkLength; i += state.needleLength) { | ||
outer: for ( | ||
let i = state.needleLength - 1; | ||
i < chunkLength; | ||
i += state.needleLength | ||
) { | ||
if (chunk[i] in state.indexes === false) { | ||
@@ -120,32 +104,14 @@ continue | ||
if (startPosition + state.needleLength > chunkLength) { | ||
if (startPosition < 0) { | ||
continue | ||
} | ||
if (startPosition < 0) { | ||
if (state.previousChunk === undefined) { | ||
continue | ||
} else if ( | ||
state.previousChunk[state.previousChunkLength + startPosition] === | ||
state.firstByte | ||
} else if (startPosition + state.needleLength > chunkLength) { | ||
if ( | ||
chunk[startPosition] === state.firstByte && | ||
chunk[chunkLength - 1] === | ||
state.needle[chunkLength - startPosition - 1] | ||
) { | ||
const newChunk = new Uint8Array( | ||
state.previousChunkLength + chunkLength, | ||
) | ||
newChunk.set(state.previousChunk) | ||
newChunk.set(chunk, state.previousChunkLength) | ||
chunk = newChunk | ||
state.previousChunk = undefined | ||
chunkLength = newChunk.length | ||
i += state.previousChunkLength | ||
const newStartPosition = state.previousChunkLength + startPosition | ||
if (state.exactMatch(chunk, newStartPosition)) { | ||
state.previousChunk = undefined | ||
emitMatch(state, chunk, newStartPosition, callback) | ||
chunk = chunk.subarray(newStartPosition + state.needleLength) | ||
chunkLength = chunk.length | ||
i = -1 | ||
continue outer | ||
} | ||
callback(state.matchIndex, chunk.subarray(0, startPosition)) | ||
state.previousChunk = chunk.subarray(startPosition) | ||
state.previousChunkLength = chunkLength - startPosition | ||
return | ||
} | ||
@@ -158,3 +124,6 @@ } else if ( | ||
) { | ||
emitMatch(state, chunk, startPosition, callback) | ||
if (startPosition > 0) { | ||
callback(state.matchIndex, chunk.subarray(0, startPosition)) | ||
} | ||
state.matchIndex += 1 | ||
chunk = chunk.subarray(startPosition + state.needleLength) | ||
@@ -168,12 +137,30 @@ chunkLength = chunkLength - startPosition - state.needleLength | ||
if (state.previousChunk !== undefined) { | ||
callback(state.matchIndex, state.previousChunk) | ||
state.previousChunk = chunk | ||
state.previousChunkLength = chunkLength | ||
} else if (chunkLength > 0) { | ||
state.previousChunk = chunk | ||
state.previousChunkLength = chunkLength | ||
} else { | ||
state.previousChunk = undefined | ||
state.previousChunkLength = 0 | ||
if (chunkLength > 0) { | ||
if (chunk[chunkLength - 1] in state.indexes) { | ||
const indexes = state.indexes[chunk[chunkLength - 1]] | ||
let earliestIndex = -1 | ||
for (let i = 0, len = indexes.length; i < len; i++) { | ||
const index = indexes[i] | ||
if ( | ||
chunk[chunkLength - 1 - index] === state.firstByte && | ||
i > earliestIndex | ||
) { | ||
earliestIndex = index | ||
} | ||
} | ||
if (earliestIndex === -1) { | ||
callback(state.matchIndex, chunk) | ||
} else { | ||
if (chunkLength - 1 - earliestIndex > 0) { | ||
callback( | ||
state.matchIndex, | ||
chunk.subarray(0, chunkLength - 1 - earliestIndex), | ||
) | ||
} | ||
state.previousChunk = chunk.subarray(chunkLength - 1 - earliestIndex) | ||
state.previousChunkLength = earliestIndex + 1 | ||
} | ||
} else { | ||
callback(state.matchIndex, chunk) | ||
} | ||
} | ||
@@ -263,5 +250,5 @@ } | ||
return { | ||
write: "Buffer" in globalThis ? writeBuffer : write, | ||
write: "Buffer" in globalThis ? writeBuffer : writeUint8Array, | ||
end, | ||
} as const | ||
} |
@@ -41,9 +41,9 @@ /// <reference types="node" /> | ||
export class MultipastaStream extends Duplex { | ||
#parser: MP.Parser | ||
#canWrite = true | ||
#writeCallback: (() => void) | undefined | ||
private _parser: MP.Parser | ||
private _canWrite = true | ||
private _writeCallback: (() => void) | undefined | ||
constructor(config: NodeConfig) { | ||
super({ readableObjectMode: true }) | ||
this.#parser = MP.make({ | ||
this._parser = MP.make({ | ||
...(config as any), | ||
@@ -57,7 +57,10 @@ onField: (info, value) => { | ||
const file = new FileStream(info) | ||
file.on("resume", this._resume.bind(this)) | ||
this.push(file) | ||
this.emit("file", file) | ||
return chunk => { | ||
this.#canWrite = file.push(chunk) | ||
this._canWrite = file.push(chunk) | ||
if (chunk === null && !this._canWrite) { | ||
this._resume() | ||
} | ||
} | ||
@@ -72,10 +75,10 @@ }, | ||
}) | ||
} | ||
this.on("drain", () => { | ||
this.#canWrite = true | ||
if (this.#writeCallback !== undefined) { | ||
this.#writeCallback() | ||
this.#writeCallback = undefined | ||
} | ||
}) | ||
_resume() { | ||
this._canWrite = true | ||
if (this._writeCallback !== undefined) { | ||
this._writeCallback() | ||
this._writeCallback = undefined | ||
} | ||
} | ||
@@ -90,14 +93,9 @@ | ||
): void { | ||
const canWrite = this.#canWrite | ||
if (chunk instanceof Uint8Array) { | ||
this.#parser.write(chunk) | ||
} else { | ||
this.#parser.write(Buffer.from(chunk, encoding)) | ||
} | ||
if (canWrite) { | ||
this._parser.write( | ||
chunk instanceof Uint8Array ? chunk : Buffer.from(chunk, encoding), | ||
) | ||
if (this._canWrite) { | ||
callback() | ||
} else { | ||
this.#writeCallback = callback | ||
this._writeCallback = callback | ||
} | ||
@@ -107,3 +105,3 @@ } | ||
_final(callback: (error?: Error | null | undefined) => void): void { | ||
this.#parser.end() | ||
this._parser.end() | ||
callback() | ||
@@ -110,0 +108,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
185629
3076