feat: add optional offset parameter to File.readBytes method

Extend File.readBytes with a second overload accepting an offset argument, allowing reads to start at any byte position from the beginning of the file. The existing single-argument variant now delegates to the new two-argument version with offset 0. Validation for the offset parameter mirrors the existing count checks, aborting on non-numeric, non-integer, or negative values. The underlying C implementation passes the offset directly to uv_fs_read, replacing the previous hardcoded zero. Documentation in the io module markdown is updated with usage examples for both signatures, and the old TODO comment about missing offset support is removed. New test files cover offset-based reads, edge cases (zero offset, past-end offset, zero count with offset), and error conditions for invalid offset arguments.
This commit is contained in:
Bob Nystrom
2015-12-30 16:13:19 +00:00
parent 00d4fca59a
commit 3746b56ed9
16 changed files with 104 additions and 18 deletions
+6
View File
@@ -10,4 +10,10 @@ System.print(file.readBytes(7)) // expect: this is
// Allows zero.
System.print(file.readBytes(0).bytes.count) // expect: 0
// A longer number reads the whole file.
System.print(file.readBytes(100)) // expect: this is a text file
// Reading past the end truncates the buffer.
System.print(file.readBytes(100).bytes.count) // expect: 19
file.close()