file

package module
v0.0.0-...-b62ffe7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 21, 2022 License: Apache-2.0 Imports: 2 Imported by: 0

README

xk6-file

k6 extension for writing files, implemented using the xk6 system.

Build

xk6 build v0.40.0 --with github.com/molochkel/xk6-file@latest

Example

import http from "k6/http";
import { check } from 'k6';
import file from 'k6/x/file';

const filepath = 'sample-output.txt';
const binaryFilepath = 'sample-image.jpg';

export default function () {
    file.writeString(filepath, 'New file. First line.\n');
    file.appendString(filepath, `Second line. VU: ${__VU}  -  ITER: ${__ITER}`);

    let response = http.get("https://upload.wikimedia.org/wikipedia/commons/3/3f/JPEG_example_flower.jpg", {
        responseType: "binary",
    });
    check(response, { 'status was 200': (r) => r.status == 200 });
    file.writeBytes(binaryFilepath, Array.from(new Uint8Array(response.body)));
}

Run sample script

./k6 run sample-script.js

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FILE

type FILE struct{}

FILE is the k6 extension

func (*FILE) AppendString

func (*FILE) AppendString(path string, s string) error

Append string to file

func (*FILE) WriteBytes

func (*FILE) WriteBytes(path string, b []byte) error

func (*FILE) WriteString

func (*FILE) WriteString(path string, s string) error

Write string to file

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL