Skip to content

acuenca-facephi/xk6-read

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

xk6-read

k6 extension for reading files and directories, implemented using the xk6 system.
Inspired in the writing files k6 extension.

Build

xk6 build v0.45.0 --with github.com/acuenca-facephi/xk6-read@latest

Local build

xk6 build v0.45.0 --with github.com/acuenca-facephi/xk6-read="/mnt/c/projects/other/xk6-read"

Example

import read from 'k6/x/read'; 

// change file/directory paths
const FILE_PATH = '/mnt/c/projects/other/test-directory/textOutput2.txt';
const DIRECTORY_PATH = '/mnt/c/projects/other/test-directory';

function readFile(file) {
    console.log(file.path + ': ' + file.content);
}

function readDirectory(directory) {
    console.log('directory :' + directory.path);
    for (let i = 0; i < directory.content.length; i++) {
        const item = directory.content[i];
        if (Array.isArray(item.content)) readDirectory(item);
        else readFile(item);
    }
}

export default function () {
    let file = read.readFile(FILE_PATH);
    //console.log(JSON.stringify(file));
    readFile(file);

    let directory = read.readDirectory(DIRECTORY_PATH);
    //console.log(JSON.stringify(directory));
    readDirectory(directory);
}

Run example script

./k6 run examples/example-script.js

Docker

Build

docker build -t adriancuenca/xk6-read:v1.0.0-rc1 .
# or
docker build --build-arg XK6_EXTENSIONS="--with github.com/grafana/xk6-output-influxdb" -t adriancuenca/xk6-read:v1.0.0-rc1 .

Run

docker run -v "/path/to/scripts:/scripts" \
-it --rm adriancuenca/xk6-read:v1.0.0-rc1 \
run /scripts/enroll_thousand_faces-xk6.js