Important: This documentation is about an older version. It's relevant only to the release noted, many of the features and functions have been updated or replaced. Please view the current version.
Returns a promise resolving to a FileInfo object with information about the file.
Example
JavaScript
import{ open, SeekMode }from'k6/experimental/fs';let file;(asyncfunction(){
file =awaitopen('bonjour.txt');})();exportdefaultasyncfunction(){// 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');}// Seek back to the beginning of the fileawait file.seek(0, SeekMode.Start);}