Skip to content

Commit

Permalink
Address pull request comments
Browse files Browse the repository at this point in the history
  • Loading branch information
oleiade committed Sep 26, 2023
1 parent cd508e5 commit 495a651
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
8 changes: 5 additions & 3 deletions examples/experimental/fs/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 4 additions & 1 deletion js/modules/k6/experimental/fs/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 495a651

Please sign in to comment.