diff --git a/src/bun.js/webcore/Body.zig b/src/bun.js/webcore/Body.zig index 2a8b087f7c..159432b662 100644 --- a/src/bun.js/webcore/Body.zig +++ b/src/bun.js/webcore/Body.zig @@ -3,7 +3,7 @@ const Body = @This(); value: Value, // = Value.empty, -pub inline fn len(this: *const Body) Blob.SizeType { +pub fn len(this: *Body) Blob.SizeType { return this.value.size(); } @@ -366,9 +366,9 @@ pub const Value = union(Tag) { } } - pub fn size(this: *const Value) Blob.SizeType { + pub fn size(this: *Value) Blob.SizeType { return switch (this.*) { - .Blob => this.Blob.size, + .Blob => @truncate(this.Blob.getSizeForBindings()), .InternalBlob => @as(Blob.SizeType, @truncate(this.InternalBlob.sliceConst().len)), .WTFStringImpl => @as(Blob.SizeType, @truncate(this.WTFStringImpl.utf8ByteLength())), .Locked => this.Locked.sizeHint(), diff --git a/test/js/web/fetch/response.test.ts b/test/js/web/fetch/response.test.ts index 452a9aa3ef..c02d148dd3 100644 --- a/test/js/web/fetch/response.test.ts +++ b/test/js/web/fetch/response.test.ts @@ -1,4 +1,5 @@ import { describe, expect, test } from "bun:test"; +import { sep } from "node:path"; test("zero args returns an otherwise empty 200 response", () => { const response = new Response(); @@ -44,3 +45,22 @@ describe("2-arg form", () => { expect(response.statusText).toBe(""); }); }); + +test("print size", () => { + expect(Bun.inspect(new Response(Bun.file(import.meta.filename)))).toMatchInlineSnapshot(` + "Response (1.81 KB) { + ok: true, + url: "", + status: 200, + statusText: "", + headers: Headers { + "content-type": "text/javascript;charset=utf-8", + }, + redirected: false, + bodyUsed: false, + FileRef ("${import.meta.dir}${sep}response.test.ts") { + type: "text/javascript;charset=utf-8" + } + }" + `); +});