diff --git a/examples/experimental/fs/fs.js b/examples/experimental/fs/fs.js index 1574acd07c6f..3d422d31983d 100644 --- a/examples/experimental/fs/fs.js +++ b/examples/experimental/fs/fs.js @@ -21,14 +21,16 @@ export default async function () { throw new Error("Unexpected file name"); } - // Define a buffer of the same size as the file - // to read the file content into. const buffer = new Uint8Array(4); let totalBytesRead = 0; - while (totalBytesRead < fileinfo.size) { + while (true) { // Read into the buffer const bytesRead = await file.read(buffer); + if (bytesRead == null) { + // EOF + break; + } // Do something useful with the content of the buffer diff --git a/js/modules/k6/experimental/fs/module.go b/js/modules/k6/experimental/fs/module.go index 23d3d4e5bbf7..f42b95f7dcfc 100644 --- a/js/modules/k6/experimental/fs/module.go +++ b/js/modules/k6/experimental/fs/module.go @@ -264,7 +264,10 @@ func (f *File) Seek(offset goja.Value, whence goja.Value) *goja.Promise { } seekMode := SeekMode(whence.ToInteger()) - if seekMode != SeekModeStart && seekMode != SeekModeCurrent && seekMode != SeekModeEnd { + switch seekMode { + case SeekModeStart, SeekModeCurrent, SeekModeEnd: + // Valid modes, do nothing. + default: reject(newFsError(TypeError, "seek() failed; reason: whence must be a SeekMode")) return promise }