k6
k6 copied to clipboard
Add a `readable` property to `fs.File` objects exposing a readable stream
With version v0.48.0 k6 introduces the k6/experimental/fs module and the ability for users to open and read from files in a normalized and efficient manner.
Solution space
We aim to benefit from our ongoing implementation of the Streams API within k6 to pursue adding a .readable property to fs.File objects. In the same fashion as Deno does, that property would return a ReadableStream of the file's content to the user.
Using it, users would be able to stream the content of the file in a standardized and simplified manner, as opposed to using our currently existing low-level API.
import { open } from 'k6/experimental/fs';
let file;
(async function () {
file = await open('bonjour.txt');
})();
export default async function () {
const fileStream = file.readable;
const reader = fileStream.getReader();
while (true) {
const { done, value } = await reader.read()
if (done) break
}
}
Definition of done
The fs.File object exposes a readable property which consists in a ReadableStream instance that allows to stream in a read-only and asynchronous fashion the content of the file.