<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>k6/experimental on Grafana Labs</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-experimental/</link><description>Recent content in k6/experimental on Grafana Labs</description><generator>Hugo -- gohugo.io</generator><language>en</language><atom:link href="/docs/k6/v2.3.x/javascript-api/k6-experimental/index.xml" rel="self" type="application/rss+xml"/><item><title>csv</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-experimental/csv/</link><pubDate>Mon, 21 Sep 2026 15:16:28 +0000</pubDate><guid>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-experimental/csv/</guid><content><![CDATA[&lt;h1 id=&#34;csv&#34;&gt;csv&lt;/h1&gt;


&lt;div data-shared=&#34;experimental-module.md&#34;&gt;
            

&lt;div class=&#34;admonition admonition-caution&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Caution&lt;/p&gt;&lt;p&gt;This is an experimental module.
&lt;br&gt;
&lt;br&gt;
While we intend to keep experimental modules as stable as possible, we may need to introduce breaking changes. This could happen at future k6 releases until the module becomes fully stable and graduates as a k6 core module. For more information, refer to the 
    &lt;a href=&#34;/docs/k6/v2.3.x/reference/versioning-and-stability-guarantees/#experimental&#34;&gt;versioning and stability guarantees document&lt;/a&gt;.
&lt;br&gt;
&lt;br&gt;
Experimental modules maintain a high level of stability and follow regular maintenance and security measures. Feel free to &lt;a href=&#34;https://github.com/grafana/k6/issues&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;open an issue&lt;/a&gt; if you have any feedback or suggestions.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;/div&gt;

        
&lt;p&gt;The &lt;code&gt;k6-experimental/csv&lt;/code&gt; module provides efficient ways to handle CSV files in k6, offering faster parsing and lower memory
usage compared to traditional JavaScript-based libraries.&lt;/p&gt;
&lt;p&gt;This module includes functionalities for both full-file parsing and streaming, allowing users to choose between
performance and memory optimization.&lt;/p&gt;
&lt;h2 id=&#34;key-features&#34;&gt;Key features&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;The 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-experimental/csv/parse/&#34;&gt;&lt;code&gt;csv.parse()&lt;/code&gt;&lt;/a&gt; function parses a complete CSV file into a SharedArray, leveraging Go-based processing for better performance and reduced memory footprint compared to JavaScript alternatives.&lt;/li&gt;
&lt;li&gt;The 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-experimental/csv/parser/&#34;&gt;&lt;code&gt;csv.Parser&lt;/code&gt;&lt;/a&gt; class is a streaming parser that reads CSV files line-by-line, optimizing memory usage and giving more control over the parsing process through a stream-like API.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;benefits&#34;&gt;Benefits&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Faster parsing&lt;/strong&gt;: The 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-experimental/csv/parse/&#34;&gt;&lt;code&gt;csv.parse()&lt;/code&gt;&lt;/a&gt; function bypasses the JavaScript runtime, significantly speeding up parsing for large CSV files.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Lower memory usage&lt;/strong&gt;: Both 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-experimental/csv/parse/&#34;&gt;&lt;code&gt;csv.parse()&lt;/code&gt;&lt;/a&gt; and 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-experimental/csv/parser/&#34;&gt;&lt;code&gt;csv.Parser&lt;/code&gt;&lt;/a&gt; support shared memory across virtual users (VUs) when using the 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-experimental/fs/open/&#34;&gt;&lt;code&gt;fs.open()&lt;/code&gt;&lt;/a&gt; function.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Flexibility&lt;/strong&gt;: Users can choose between full-file parsing with 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-experimental/csv/parse/&#34;&gt;&lt;code&gt;csv.parse&lt;/code&gt;&lt;/a&gt; for speed or line-by-line streaming with 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-experimental/csv/parser/&#34;&gt;&lt;code&gt;csv.Parser&lt;/code&gt;&lt;/a&gt; for memory efficiency.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;trade-offs&#34;&gt;Trade-offs&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;The 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-experimental/csv/parse/&#34;&gt;&lt;code&gt;csv.parse()&lt;/code&gt;&lt;/a&gt; function parses the entire file during the initialization phase, which might increase startup time and memory usage for large files. Best for scenarios where performance is more important than memory consumption.&lt;/li&gt;
&lt;li&gt;The 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-experimental/csv/parser/&#34;&gt;&lt;code&gt;csv.Parser&lt;/code&gt;&lt;/a&gt; class processes the file line-by-line, making it more memory-efficient but potentially slower due to the overhead of reading each line. Suitable for scenarios where memory usage is critical or more granular control over parsing is needed.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;api&#34;&gt;API&lt;/h2&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Function/Object&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-experimental/csv/parse/&#34;&gt;parse&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Parses an entire CSV file into a SharedArray for high-performance scenarios.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-experimental/csv/parser/&#34;&gt;Parser&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;A class for streaming CSV parsing, allowing line-by-line reading with minimal memory consumption.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-experimental/csv/options/&#34;&gt;Options&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;An object that describes the configuration available for the operation of parsing CSV files using the 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-experimental/csv/parse/&#34;&gt;&lt;code&gt;parse()&lt;/code&gt;&lt;/a&gt; function and the 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-experimental/csv/parser/&#34;&gt;&lt;code&gt;csv.Parser&lt;/code&gt;&lt;/a&gt; class.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h2 id=&#34;example&#34;&gt;Example&lt;/h2&gt;
&lt;h3 id=&#34;parsing-a-full-csv-file-into-a-sharedarray&#34;&gt;Parsing a full CSV File into a SharedArray&lt;/h3&gt;
&lt;!--md-k6:skip--&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import { open } from &amp;#39;k6/experimental/fs&amp;#39;;
import csv from &amp;#39;k6/experimental/csv&amp;#39;;
import { scenario } from &amp;#39;k6/execution&amp;#39;;

export const options = {
  iterations: 10,
};

const file = await open(&amp;#39;data.csv&amp;#39;);

// The `csv.parse` function consumes the entire file at once and returns
// the parsed records as a `SharedArray` object.
const csvRecords = await csv.parse(file, { delimiter: &amp;#39;,&amp;#39; });

export default async function () {
  // `csvRecords` is a `SharedArray`. Each element is a record from the CSV file, represented as an array
  // where each element is a field from the CSV record.
  //
  // Thus, `csvRecords[scenario.iterationInTest]` will give us the record for the current iteration.
  console.log(csvRecords[scenario.iterationInTest]);
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;streaming-a-csv-file-line-by-line&#34;&gt;Streaming a CSV file line-by-line&lt;/h3&gt;
&lt;!--md-k6:skip--&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import { open } from &amp;#39;k6/experimental/fs&amp;#39;;
import csv from &amp;#39;k6/experimental/csv&amp;#39;;

export const options = {
  iterations: 10,
};

const file = await open(&amp;#39;data.csv&amp;#39;);

// The `csv.parse` function consumes the entire file at once and returns
// the parsed records as a `SharedArray` object.
const parser = new csv.Parser(file);

export default async function () {
  // The parser `next` method attempts to read the next row from the CSV file.
  //
  // It returns an iterator-like object with a `done` property that indicates whether
  // there are more rows to read, and a `value` property that contains the row fields
  // as an array.
  const { done, value } = await parser.next();
  if (done) {
    throw new Error(&amp;#39;No more rows to read&amp;#39;);
  }

  // We expect the `value` property to be an array of strings, where each string is a field
  // from the CSV record.
  console.log(done, value);
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
]]></content><description>&lt;h1 id="csv">csv&lt;/h1>
&lt;div data-shared="experimental-module.md">
&lt;div class="admonition admonition-caution">&lt;blockquote>&lt;p class="title text-uppercase">Caution&lt;/p>&lt;p>This is an experimental module.
&lt;br>
&lt;br>
While we intend to keep experimental modules as stable as possible, we may need to introduce breaking changes. This could happen at future k6 releases until the module becomes fully stable and graduates as a k6 core module. For more information, refer to the
&lt;a href="/docs/k6/v2.3.x/reference/versioning-and-stability-guarantees/#experimental">versioning and stability guarantees document&lt;/a>.
&lt;br>
&lt;br>
Experimental modules maintain a high level of stability and follow regular maintenance and security measures. Feel free to &lt;a href="https://github.com/grafana/k6/issues" target="_blank" rel="noopener noreferrer">open an issue&lt;/a> if you have any feedback or suggestions.&lt;/p></description></item><item><title>fs</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-experimental/fs/</link><pubDate>Mon, 21 Sep 2026 15:16:28 +0000</pubDate><guid>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-experimental/fs/</guid><content><![CDATA[&lt;h1 id=&#34;fs&#34;&gt;fs&lt;/h1&gt;


&lt;div data-shared=&#34;experimental-module.md&#34;&gt;
            

&lt;div class=&#34;admonition admonition-caution&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Caution&lt;/p&gt;&lt;p&gt;This is an experimental module.
&lt;br&gt;
&lt;br&gt;
While we intend to keep experimental modules as stable as possible, we may need to introduce breaking changes. This could happen at future k6 releases until the module becomes fully stable and graduates as a k6 core module. For more information, refer to the 
    &lt;a href=&#34;/docs/k6/v2.3.x/reference/versioning-and-stability-guarantees/#experimental&#34;&gt;versioning and stability guarantees document&lt;/a&gt;.
&lt;br&gt;
&lt;br&gt;
Experimental modules maintain a high level of stability and follow regular maintenance and security measures. Feel free to &lt;a href=&#34;https://github.com/grafana/k6/issues&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;open an issue&lt;/a&gt; if you have any feedback or suggestions.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;/div&gt;

        
&lt;p&gt;The k6 filesystem experimental module provides a memory-efficient way to handle file interactions within your test scripts. It currently offers support for opening files, reading their content, seeking through their content, and retrieving metadata about them.&lt;/p&gt;
&lt;h3 id=&#34;memory-efficiency&#34;&gt;Memory efficiency&lt;/h3&gt;
&lt;p&gt;One of the key advantages of the filesystem module is its memory efficiency. Unlike the traditional 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/init-context/open/&#34;&gt;open&lt;/a&gt; function, which loads a file multiple times into memory, the filesystem module reduces memory usage by loading the file as little as possible and sharing the same memory space between all VUs. This approach reduces the risk of encountering out-of-memory errors, especially in load tests involving large files.&lt;/p&gt;
&lt;h3 id=&#34;notes-on-usage&#34;&gt;Notes on usage&lt;/h3&gt;
&lt;p&gt;An important consideration when using the filesystem module is its handling of external file modifications. Once k6 loads a file, it behaves like a &amp;ldquo;view&amp;rdquo; over its contents. If you modify the underlying file during a test, k6 will not reflect those changes in the loaded 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-experimental/fs/file/&#34;&gt;File&lt;/a&gt; instance.&lt;/p&gt;
&lt;h2 id=&#34;api-overview&#34;&gt;API Overview&lt;/h2&gt;
&lt;p&gt;The module exports functions and objects to interact with the file system:&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Function/Object&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-experimental/fs/open/&#34;&gt;open&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Opens a file and returns a promise resolving to a &lt;code&gt;File&lt;/code&gt; instance.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-experimental/fs/file/&#34;&gt;File&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Represents a file with methods for reading, seeking, and obtaining file stats.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-experimental/fs/seekmode/&#34;&gt;SeekMode&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Enum for specifying the reference point for seek operations. Includes &lt;code&gt;Start&lt;/code&gt;, &lt;code&gt;Current&lt;/code&gt;, and &lt;code&gt;End&lt;/code&gt;.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h2 id=&#34;example&#34;&gt;Example&lt;/h2&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import { open, SeekMode } from &amp;#39;k6/experimental/fs&amp;#39;;

const file = await open(&amp;#39;bonjour.txt&amp;#39;);

export default async function () {
  // Seek to the beginning of the file
  await file.seek(0, SeekMode.Start);

  // About information about the file
  const fileinfo = await file.stat();
  if (fileinfo.name != &amp;#39;bonjour.txt&amp;#39;) {
    throw new Error(&amp;#39;Unexpected file name&amp;#39;);
  }

  const buffer = new Uint8Array(4);

  let totalBytesRead = 0;
  while (true) {
    // Read into the buffer
    const bytesRead = await file.read(buffer);
    if (bytesRead == null) {
      // EOF
      break;
    }

    // Do something useful with the content of the buffer
    totalBytesRead &amp;#43;= bytesRead;

    // If bytesRead is less than the buffer size, we&amp;#39;ve read the whole file
    if (bytesRead &amp;lt; buffer.byteLength) {
      break;
    }
  }

  // Check that we read the expected number of bytes
  if (totalBytesRead != fileinfo.size) {
    throw new Error(&amp;#39;Unexpected number of bytes read&amp;#39;);
  }
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
]]></content><description>&lt;h1 id="fs">fs&lt;/h1>
&lt;div data-shared="experimental-module.md">
&lt;div class="admonition admonition-caution">&lt;blockquote>&lt;p class="title text-uppercase">Caution&lt;/p>&lt;p>This is an experimental module.
&lt;br>
&lt;br>
While we intend to keep experimental modules as stable as possible, we may need to introduce breaking changes. This could happen at future k6 releases until the module becomes fully stable and graduates as a k6 core module. For more information, refer to the
&lt;a href="/docs/k6/v2.3.x/reference/versioning-and-stability-guarantees/#experimental">versioning and stability guarantees document&lt;/a>.
&lt;br>
&lt;br>
Experimental modules maintain a high level of stability and follow regular maintenance and security measures. Feel free to &lt;a href="https://github.com/grafana/k6/issues" target="_blank" rel="noopener noreferrer">open an issue&lt;/a> if you have any feedback or suggestions.&lt;/p></description></item><item><title>streams</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-experimental/streams/</link><pubDate>Mon, 21 Sep 2026 15:16:28 +0000</pubDate><guid>https://grafana.com/docs/k6/v2.3.x/javascript-api/k6-experimental/streams/</guid><content><![CDATA[&lt;h1 id=&#34;streams&#34;&gt;streams&lt;/h1&gt;


&lt;div data-shared=&#34;experimental-module.md&#34;&gt;
            

&lt;div class=&#34;admonition admonition-caution&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Caution&lt;/p&gt;&lt;p&gt;This is an experimental module.
&lt;br&gt;
&lt;br&gt;
While we intend to keep experimental modules as stable as possible, we may need to introduce breaking changes. This could happen at future k6 releases until the module becomes fully stable and graduates as a k6 core module. For more information, refer to the 
    &lt;a href=&#34;/docs/k6/v2.3.x/reference/versioning-and-stability-guarantees/#experimental&#34;&gt;versioning and stability guarantees document&lt;/a&gt;.
&lt;br&gt;
&lt;br&gt;
Experimental modules maintain a high level of stability and follow regular maintenance and security measures. Feel free to &lt;a href=&#34;https://github.com/grafana/k6/issues&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;open an issue&lt;/a&gt; if you have any feedback or suggestions.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;/div&gt;

        
&lt;p&gt;The k6 streams experimental module provides an implementation of the Streams API specification, providing a way to define and consume streams of data within your test scripts. It currently implements a subset of the full specification, and offers support for defining and consuming readable streams.&lt;/p&gt;
&lt;h2 id=&#34;concepts-and-usage&#34;&gt;Concepts and usage&lt;/h2&gt;
&lt;p&gt;Streaming involves breaking a resource that one wants to process or consume into smaller chunks, which can be processed or consumed incrementally. This is particularly useful when dealing with large files or data sources, as it allows you to work with the data in smaller, more manageable pieces.&lt;/p&gt;
&lt;p&gt;With the Streams API support in k6, you can start processing raw data with Javascript bit by bit, as soon as it&amp;rsquo;s available, without needing to generate a full in-memory representation of the data. This helps to reduce memory usage and improve performance, especially when working with large data sets.&lt;/p&gt;
&lt;h2 id=&#34;api-overview&#34;&gt;API Overview&lt;/h2&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Class&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-experimental/streams/readablestream/&#34;&gt;ReadableStream&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Represents a readable stream of data.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h2 id=&#34;example&#34;&gt;Example&lt;/h2&gt;
&lt;!-- md-k6:skip --&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import { open } from &amp;#39;k6/experimental/fs&amp;#39;;
import { ReadableStream } from &amp;#39;k6/experimental/streams&amp;#39;;

// Open a csv file containing the data to be read
const file = await open(&amp;#39;./data.csv&amp;#39;);

export default async function () {
  let lineReaderState;

  // Define a ReadableStream that reads lines from the file
  // and parses them into objects with name and color properties.
  const fileLinesStream = new ReadableStream({
    // The start function is called when the readable stream is
    // created. In here, you can connect to the data source
    // and perform administrative tasks.
    async start(controller) {
      lineReaderState = {
        buffer: new Uint8Array(1024),
        decoder: new TextDecoder(),
        remaining: &amp;#39;&amp;#39;,
      };
    },

    // The pull function is called repeatedly to get data, while the
    // internal high water mark is not reached.
    async pull(controller) {
      const line = await getNextLine(file, lineReaderState);
      if (line === null) {
        controller.close();
        return;
      }

      const [name, color] = line.split(&amp;#39;,&amp;#39;);
      controller.enqueue({ name, color });
    },
  });

  // Obtain and lock a reader to the stream
  const reader = fileLinesStream.getReader();

  try {
    // Read and process each item from the stream
    while (true) {
      const { done, value } = await reader.read();
      if (done) {
        break;
      }

      console.log(value);
    }
  } catch (error) {
    console.error(&amp;#39;Stream reading failed: &amp;#39;, error);
  }
}

// getNextLine reads the next line from the file and returns it.
//
// It reads the file in chunks and buffers the remaining data
// to handle partial lines. It returns null when there are no
// more lines to read.
async function getNextLine(file, state) {
  while (true) {
    if (state.remaining.includes(&amp;#39;\n&amp;#39;)) {
      const lineEndIndex = state.remaining.indexOf(&amp;#39;\n&amp;#39;);
      const line = state.remaining.substring(0, lineEndIndex).trim();

      state.remaining = state.remaining.substring(lineEndIndex &amp;#43; 1);

      if (line) {
        return line;
      }
    } else {
      const bytesRead = await file.read(state.buffer);
      if (bytesRead === null) {
        // EOF
        state.remaining &amp;#43;= state.decoder.decode();

        if (state.remaining) {
          const finalLine = state.remaining.trim();

          // Clear remaining to signal the end
          state.remaining = &amp;#39;&amp;#39;;

          // Return the last non-empty line
          return finalLine;
        }

        // Indicate that there are no more lines to read
        return null;
      }

      state.remaining &amp;#43;= state.decoder.decode(state.buffer.subarray(0, bytesRead), {
        stream: true,
      });
    }
  }
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
]]></content><description>&lt;h1 id="streams">streams&lt;/h1>
&lt;div data-shared="experimental-module.md">
&lt;div class="admonition admonition-caution">&lt;blockquote>&lt;p class="title text-uppercase">Caution&lt;/p>&lt;p>This is an experimental module.
&lt;br>
&lt;br>
While we intend to keep experimental modules as stable as possible, we may need to introduce breaking changes. This could happen at future k6 releases until the module becomes fully stable and graduates as a k6 core module. For more information, refer to the
&lt;a href="/docs/k6/v2.3.x/reference/versioning-and-stability-guarantees/#experimental">versioning and stability guarantees document&lt;/a>.
&lt;br>
&lt;br>
Experimental modules maintain a high level of stability and follow regular maintenance and security measures. Feel free to &lt;a href="https://github.com/grafana/k6/issues" target="_blank" rel="noopener noreferrer">open an issue&lt;/a> if you have any feedback or suggestions.&lt;/p></description></item></channel></rss>