aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-11-25 03:02:45 -0800
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-11-25 03:02:45 -0800
commit7a193ed243732f2bb606dc8f0c87d77058f9fff3 (patch)
tree984ec05896e9a5234b98c755f5ef3ba9009b0ab8
parentc168c70e60727ee5ececd33ecbfa157a161d9dbf (diff)
downloadbun-7a193ed243732f2bb606dc8f0c87d77058f9fff3.tar.gz
bun-7a193ed243732f2bb606dc8f0c87d77058f9fff3.tar.zst
bun-7a193ed243732f2bb606dc8f0c87d77058f9fff3.zip
[behavior change] Bun.file().size now always reports a number
-rw-r--r--src/bun.js/webcore/response.zig38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/bun.js/webcore/response.zig b/src/bun.js/webcore/response.zig
index f5cbf860e..121078210 100644
--- a/src/bun.js/webcore/response.zig
+++ b/src/bun.js/webcore/response.zig
@@ -3246,7 +3246,45 @@ pub const Blob = struct {
this.offset = @minimum(store_size, offset);
this.size = store_size - offset;
}
+
+ return;
+ } else if (store.data == .file) {
+ if (store.data.file.seekable == null) {
+ if (store.data.file.pathlike == .path) {
+ var buffer: [bun.MAX_PATH_BYTES]u8 = undefined;
+ switch (JSC.Node.Syscall.stat(store.data.file.pathlike.path.sliceZ(&buffer))) {
+ .result => |stat| {
+ store.data.file.max_size = @truncate(SizeType, @intCast(u64, @maximum(stat.size, 0)));
+ store.data.file.mode = stat.mode;
+ store.data.file.seekable = std.os.S.ISREG(stat.mode);
+ },
+ // the file may not exist yet. Thats's okay.
+ else => {},
+ }
+ } else if (store.data.file.pathlike == .fd) {
+ switch (JSC.Node.Syscall.fstat(store.data.file.pathlike.fd)) {
+ .result => |stat| {
+ store.data.file.max_size = @truncate(SizeType, @intCast(u64, @maximum(stat.size, 0)));
+ store.data.file.mode = stat.mode;
+ store.data.file.seekable = std.os.S.ISREG(stat.mode);
+ },
+ // the file may not exist yet. Thats's okay.
+ else => {},
+ }
+ }
+ }
+
+ if (store.data.file.seekable != null) {
+ const store_size = store.data.file.max_size;
+ const offset = this.offset;
+
+ this.offset = @minimum(store_size, offset);
+ this.size = store_size - offset;
+ return;
+ }
}
+
+ this.size = 0;
} else {
this.size = 0;
}