Skip to content

streams: Add support for non static compose #43664

Description

@rluvaton

What is the problem this feature will solve?

It will make the code much easier to read/write when the current readable operators are not enough

What is the feature you are proposing to solve the problem?

Adding a non-static compose method so we can chain multiple operators together

it would like like this for example:

fs.createReadStream("./file.pcapng")
  .compose(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();

What alternatives have you considered?

Using static compose

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues requesting new Node.js features.streamIssues and PRs related to Node.js streams.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions