Open source


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.


offsetnumberThe offset in bytes from the position specified by whence.
whenceSeekModeThe position from which the offset is applied.


A Promise resolving to the new offset within the file.


import { open, SeekMode } from 'k6/experimental/fs';

let file;
(async function () {
  file = await open('bonjour.txt');

export default async function () {
  // Seek 6 bytes from the start of the file
  await, SeekMode.Start);

  // Seek 2 more bytes from the current position
  await, SeekMode.Current);

  // Seek backwards 2 bytes from the end of the file
  await, SeekMode.End);