Documentation for automated readers
A curated documentation index is available at: https://grafana.com/llms.txt
A complete documentation index is available at: https://grafana.com/llms-full.txt
These indexes can help with page discovery before fetching individual documents.
This page is also available in Markdown, which may be easier for automated readers and AI tools to parse than HTML. The Markdown version is available at https://grafana.com/docs/k6/next/javascript-api/k6-experimental/fs/file/seek.md, or by sending Accept: text/markdown to https://grafana.com/docs/k6/next/javascript-api/k6-experimental/fs/file/seek/. For broader documentation discovery, the curated index is available at https://grafana.com/llms.txt and the complete index is available at https://grafana.com/llms-full.txt.
This is documentation for the next version of Grafana k6 documentation. For the latest stable release, go to the latest version.
seek
The seek method sets the file position indicator for the file to the passed offset bytes, under the mode given by whence. The call resolves to the new position within the resource (bytes from the start).
Based on the SeekMode passed, the offset is interpreted as follows:
- when using
SeekMode.Start, the offset must be greater than or equal to zero. - when using
SeekMode.Current, the offset can be positive or negative. - when using
SeekMode.End, the offset must be less than or equal to zero.
Parameters
| Parameter | Type | Description |
|---|---|---|
| offset | number | The offset in bytes from the position specified by whence. |
| whence | SeekMode | The position from which the offset is applied. |
Returns
A Promise resolving to the new offset within the file.
Example
import { open, SeekMode } from 'k6/experimental/fs';
const file = await open('bonjour.txt');
export default async function () {
// Seek 6 bytes from the start of the file
await file.seek(6, SeekMode.Start);
// Seek 2 more bytes from the current position
await file.seek(2, SeekMode.Current);
// Seek backwards 2 bytes from the end of the file
await file.seek(-2, SeekMode.End);
}Was this page helpful?
Related resources from Grafana Labs

