aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/bun.js/webcore/blob.zig22
-rw-r--r--test/bun.js/bun-write.test.js8
-rw-r--r--test/bun.js/emptyFile0
3 files changed, 23 insertions, 7 deletions
diff --git a/src/bun.js/webcore/blob.zig b/src/bun.js/webcore/blob.zig
index c0a865d5d..ae60ef01f 100644
--- a/src/bun.js/webcore/blob.zig
+++ b/src/bun.js/webcore/blob.zig
@@ -73,6 +73,8 @@ const PathOrBlob = union(enum) {
};
pub const Blob = struct {
+ const bloblog = Output.scoped(.Blob, false);
+
pub usingnamespace JSC.Codegen.JSBlob;
size: SizeType = 0,
@@ -1431,9 +1433,10 @@ pub const Blob = struct {
this.doClose();
}
- var io_task = this.io_task.?;
- this.io_task = null;
- io_task.onFinish();
+ if (this.io_task) |io_task| {
+ io_task.onFinish();
+ this.io_task = null;
+ }
}
fn resolveSize(this: *ReadFile, fd: bun.FileDescriptor) void {
@@ -1655,9 +1658,10 @@ pub const Blob = struct {
this.doClose();
}
- var io_task = this.io_task.?;
- this.io_task = null;
- io_task.onFinish();
+ if (this.io_task) |io_task| {
+ io_task.onFinish();
+ this.io_task = null;
+ }
}
fn runWithFD(this: *WriteFile, fd: bun.FileDescriptor) void {
@@ -2825,6 +2829,8 @@ pub const Blob = struct {
}
pub fn doReadFile(this: *Blob, comptime Function: anytype, global: *JSGlobalObject) JSValue {
+ bloblog("doReadFile", .{});
+
const Handler = NewReadFileHandler(Function);
var promise = JSPromise.create(global);
@@ -2849,6 +2855,7 @@ pub const Blob = struct {
) catch unreachable;
var read_file_task = Store.ReadFile.ReadFileTask.createOnJSThread(bun.default_allocator, global, file_read) catch unreachable;
read_file_task.schedule();
+ bloblog("doReadFile: read_file_task scheduled", .{});
return promise_value;
}
@@ -3009,12 +3016,13 @@ pub const Blob = struct {
}
pub fn toArrayBuffer(this: *Blob, global: *JSGlobalObject, comptime lifetime: Lifetime) JSValue {
+ bloblog("toArrayBuffer", .{});
if (this.needsToReadFile()) {
return this.doReadFile(toArrayBufferWithBytes, global);
}
var view_ = this.sharedView();
-
+ bloblog("sharedView {d}", .{view_.len});
if (view_.len == 0)
return JSC.ArrayBuffer.create(global, "", .ArrayBuffer);
diff --git a/test/bun.js/bun-write.test.js b/test/bun.js/bun-write.test.js
index 7e1d43059..68e221d51 100644
--- a/test/bun.js/bun-write.test.js
+++ b/test/bun.js/bun-write.test.js
@@ -139,6 +139,14 @@ it("Bun.file", async () => {
await gcTick();
});
+it("Bun.file empty file", async () => {
+ const file = path.join(import.meta.dir, "emptyFile");
+ await gcTick();
+ const buffer = await Bun.file(file).arrayBuffer()
+ expect(buffer.byteLength).toBe(0);
+ await gcTick();
+});
+
it("Bun.file as a Blob", async () => {
const filePath = path.join(import.meta.path, "../fetch.js.txt");
const fixture = fs.readFileSync(filePath, "utf8");
diff --git a/test/bun.js/emptyFile b/test/bun.js/emptyFile
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/test/bun.js/emptyFile