Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/avitalique/xk6-file
k6 extension for writing files
https://github.com/avitalique/xk6-file
k6 k6-extension xk6
Last synced: 11 days ago
JSON representation
k6 extension for writing files
- Host: GitHub
- URL: https://github.com/avitalique/xk6-file
- Owner: avitalique
- License: apache-2.0
- Created: 2021-03-26T21:56:30.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-06-10T09:29:32.000Z (5 months ago)
- Last Synced: 2024-07-30T21:05:34.222Z (3 months ago)
- Topics: k6, k6-extension, xk6
- Language: Go
- Homepage:
- Size: 29.3 KB
- Stars: 23
- Watchers: 2
- Forks: 12
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
- awesome-k6 - xk6-file - Write files. (Extensions / Community)
README
# xk6-file
[k6](https://github.com/grafana/k6) extension for writing files, implemented using the
[xk6](https://github.com/grafana/xk6) system.## Build
```shell
xk6 build v0.54.0 --with github.com/avitalique/xk6-file@latest
```## Example
```javascript
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
```shell
./k6 run examples/sample-script.js
```