Returns a promise resolving to a
FileInfo object with information about the file.
Example
JavaScript
import{ open, SeekMode }from'k6/experimental/fs';const file =awaitopen('bonjour.txt');exportdefaultasyncfunction(){// Seek to the beginning of the fileawait file.seek(0, SeekMode.Start);// About information about the fileconst fileinfo =await file.stat();if(fileinfo.name !='bonjour.txt'){thrownewError('Unexpected file name');}const buffer =newUint8Array(4);let totalBytesRead =0;while(true){// Read into the bufferconst bytesRead =await file.read(buffer);if(bytesRead ==null){// EOFbreak;}// Do something useful with the content of the buffer
totalBytesRead += bytesRead;// If bytesRead is less than the buffer size, we've read the whole fileif(bytesRead < buffer.byteLength){break;}}// Check that we read the expected number of bytesif(totalBytesRead != fileinfo.size){thrownewError('Unexpected number of bytes read');}}