aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/io/io_darwin.zig6
-rw-r--r--test/js/bun/io/bun-write.test.js9
2 files changed, 15 insertions, 0 deletions
diff --git a/src/io/io_darwin.zig b/src/io/io_darwin.zig
index 226a4d284..cb2d15afb 100644
--- a/src/io/io_darwin.zig
+++ b/src/io/io_darwin.zig
@@ -1350,6 +1350,12 @@ pub fn read(
struct {
fn doOperation(op: anytype) ReadError!usize {
while (true) {
+ if (op.positional) {
+ const rc = os.system.lseek(op.fd, @intCast(op.offset), 0);
+ if (rc == -1) {
+ return error.Unseekable;
+ }
+ }
const rc = os.system.read(
op.fd,
op.buf,
diff --git a/test/js/bun/io/bun-write.test.js b/test/js/bun/io/bun-write.test.js
index b67df9405..f435d2ceb 100644
--- a/test/js/bun/io/bun-write.test.js
+++ b/test/js/bun/io/bun-write.test.js
@@ -291,6 +291,15 @@ it.skip("Bun.write('output.html', HTMLRewriter.transform(Bun.file)))", async don
done();
});
+it("offset should work #4963", async () => {
+ const filename = tmpdir() + "/bun.test.offset.txt";
+ await Bun.write(filename, "contents");
+ const file = Bun.file(filename);
+ const slice = file.slice(2, file.size);
+ const contents = await slice.text();
+ expect(contents).toBe("ntents");
+});
+
it("#2674", async () => {
const file = path.join(import.meta.dir, "big-stdout.js");