Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement the ReadableStream.pipeThrough method #3921

Open
Tracked by #3920
oleiade opened this issue Aug 28, 2024 · 0 comments
Open
Tracked by #3920

Implement the ReadableStream.pipeThrough method #3921

oleiade opened this issue Aug 28, 2024 · 0 comments
Labels

Comments

@oleiade
Copy link
Member

oleiade commented Aug 28, 2024

Feature Description

Description

As part of our ongoing efforts to improve k6’s streaming capabilities, we propose adding support for the ReadableStream.pipeThrough method. This method is a key feature of the Streams API, allowing ReadableStream instances to be easily piped through TransformStream objects, creating a powerful and flexible way to process data streams in k6.

Background and prerequisites

Currently, k6 supports ReadableStream but lacks support for TransformStream and the pipeThrough method, limiting the ability to build complex streaming data processing pipelines. pipeThrough provides a convenient and declarative way to connect ReadableStream to TransformStream, greatly simplifying the code needed for stream transformations.

Implementing pipeThrough is tied to supporting TransformStream, as the two features are designed to work together.

Usage example

Once TransformStream and pipeThrough are implemented, the following example would be possible:

// Step 1: Create a readable stream (e.g., from a file or network response)
const readableStream = getReadableStreamSomehow();

// Step 2: Define a simple transform stream to modify the data
const transformStream = new TransformStream({
  transform(chunk, controller) {
    // Example transformation: Convert all text to uppercase
    controller.enqueue(chunk.toUpperCase());
  },
});

// Step 3: Pipe the readable stream through the transform stream
readableStream
  .pipeThrough(transformStream)
  .getReader()
  .read()
  .then(({ done, value }) => {
    if (!done) {
      console.log('Transformed Value:', value);
    }
  });

Suggested Solution (optional)

No response

Already existing or connected issues / PRs (optional)

depends on #3919
#3920
#2974

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant