file

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

README

xk6-file

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

Build

xk6 build v0.46.0 --with github.com/avitalique/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 () {
    // Write/append string to file
    file.writeString(filepath, 'New file. First line.\n');
    file.appendString(filepath, `Second line. VU: ${__VU}  -  ITER: ${__ITER}`);

    // Remove rows from text file/clear file content/delete file
    file.removeRowsBetweenValues(filepath, 2, 2);
    file.clearFile(filepath);
    file.deleteFile(filepath);

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

Run sample script

./k6 run examples/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

AppendString appends string to file

func (*FILE) ClearFile

func (*FILE) ClearFile(path string) error

ClearFile removes all the contents of a file

func (*FILE) DeleteFile

func (*FILE) DeleteFile(path string) error

DeleteFile deletes file

func (*FILE) RemoveRowsBetweenValues

func (*FILE) RemoveRowsBetweenValues(path string, start, end int) error

RemoveRowsBetweenValues removes the rows from a file between start and end (inclusive)

func (FILE) RenameFile

func (FILE) RenameFile(oldPath string, newPath string) error

RenameFile renames file from oldPath to newPath

func (*FILE) WriteBytes

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

WriteBytes writes binary file

func (*FILE) WriteString

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

WriteString writes string to file

Jump to

Keyboard shortcuts

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