Merge pull request #1632 from lightpanda-io/Response_arrayBuffer
Some checks failed
e2e-test / zig build release (push) Has been cancelled
e2e-test / demo-scripts (push) Has been cancelled
e2e-test / cdp-and-hyperfine-bench (push) Has been cancelled
e2e-test / perf-fmt (push) Has been cancelled
e2e-test / browser fetch (push) Has been cancelled
zig-test / zig test using v8 in debug mode (push) Has been cancelled
zig-test / zig test (push) Has been cancelled
zig-test / perf-fmt (push) Has been cancelled
nightly build / build-linux-x86_64 (push) Has been cancelled
nightly build / build-linux-aarch64 (push) Has been cancelled
nightly build / build-macos-aarch64 (push) Has been cancelled
nightly build / build-macos-x86_64 (push) Has been cancelled
wpt / web platform tests json output (push) Has been cancelled
wpt / perf-fmt (push) Has been cancelled
e2e-integration-test / zig build release (push) Has been cancelled
e2e-integration-test / demo-integration-scripts (push) Has been cancelled

Add Response.arrayBuffer()
This commit is contained in:
Karl Seguin
2026-02-24 07:27:20 +08:00
committed by GitHub
2 changed files with 12 additions and 0 deletions

View File

@@ -180,6 +180,13 @@
testing.expectEqual(true, response.body !== null); testing.expectEqual(true, response.body !== null);
testing.expectEqual(true, response.body instanceof ReadableStream); testing.expectEqual(true, response.body instanceof ReadableStream);
const buf = await response.arrayBuffer()
restore();
const uint8array = new Uint8Array(buf);
const decoder = new TextDecoder('utf-8');
testing.expectEqual('1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890', decoder.decode(uint8array));
}); });
</script> </script>

View File

@@ -143,6 +143,10 @@ pub fn getJson(self: *Response, page: *Page) !js.Promise {
return local.resolvePromise(try value.persist()); return local.resolvePromise(try value.persist());
} }
pub fn arrayBuffer(self: *const Response, page: *Page) !js.Promise {
return page.js.local.?.resolvePromise(js.ArrayBuffer{ .values = self._body orelse "" });
}
pub const JsApi = struct { pub const JsApi = struct {
pub const bridge = js.Bridge(Response); pub const bridge = js.Bridge(Response);
@@ -165,6 +169,7 @@ pub const JsApi = struct {
pub const body = bridge.accessor(Response.getBody, null, .{}); pub const body = bridge.accessor(Response.getBody, null, .{});
pub const url = bridge.accessor(Response.getURL, null, .{}); pub const url = bridge.accessor(Response.getURL, null, .{});
pub const redirected = bridge.accessor(Response.isRedirected, null, .{}); pub const redirected = bridge.accessor(Response.isRedirected, null, .{});
pub const arrayBuffer = bridge.function(Response.arrayBuffer, .{});
}; };
const testing = @import("../../../testing.zig"); const testing = @import("../../../testing.zig");