diff options
author | 2023-09-11 21:19:43 -0300 | |
---|---|---|
committer | 2023-09-11 17:19:43 -0700 | |
commit | c9a0ea96cd13df39fdfc4c1ebb897453517718f3 (patch) | |
tree | 1f2e85e1e0024f7a2134e0452b01d92e08033544 | |
parent | ca461f9e83b2c692442bb7e20c2f9e3670d2ef6a (diff) | |
download | bun-c9a0ea96cd13df39fdfc4c1ebb897453517718f3.tar.gz bun-c9a0ea96cd13df39fdfc4c1ebb897453517718f3.tar.zst bun-c9a0ea96cd13df39fdfc4c1ebb897453517718f3.zip |
fix(BunFile) .slice offset on macOS (#4991)
* fix offset
* simplify error
-rw-r--r-- | src/io/io_darwin.zig | 6 | ||||
-rw-r--r-- | test/js/bun/io/bun-write.test.js | 9 |
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"); |