Created
June 30, 2022 05:40
-
-
Save rluvaton/81f19472875976a4ec6e6e890bd8139d to your computer and use it in GitHub Desktop.
UseTransformer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fs.readFileStream("./file.pcapng") | |
.useTransform(async function* (source) { | |
let block = Buffer.alloc(0); | |
for await (const chunk of source) { | |
block = Buffer.concat(block, chunk); | |
if (block.length < REQUIRED_BLOCK_SIZE_TO_GET_TO_TOTAL_LENGTH) { | |
continue; | |
} | |
const blockExpectedTotalSize = getTotalSizeFromBlock(block); | |
if (block.length < blockExpectedTotalSize) { | |
continue; | |
} | |
if (mergedBlock.length >= blockExpectedTotalSize) { | |
yield block.slice(0, blockExpectedTotalSize); | |
block = block.slice(blockExpectedTotalSize); | |
} | |
} | |
}) | |
.map((blockBuffer) => parseBufferBasedOnBlockType(blockBuffer)) | |
.filter((parsedBlock) => parsedblock.dest === "192.168.1.1") | |
.toArray(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment