mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-03-22 04:34:44 +00:00
Add Response.arrayBuffer()
This commit is contained in:
@@ -180,6 +180,13 @@
|
||||
|
||||
testing.expectEqual(true, response.body !== null);
|
||||
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>
|
||||
|
||||
|
||||
@@ -145,6 +145,10 @@ pub fn getJson(self: *Response, page: *Page) !js.Promise {
|
||||
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 bridge = js.Bridge(Response);
|
||||
|
||||
@@ -167,6 +171,7 @@ pub const JsApi = struct {
|
||||
pub const body = bridge.accessor(Response.getBody, null, .{});
|
||||
pub const url = bridge.accessor(Response.getURL, null, .{});
|
||||
pub const redirected = bridge.accessor(Response.isRedirected, null, .{});
|
||||
pub const arrayBuffer = bridge.function(Response.arrayBuffer, .{});
|
||||
};
|
||||
|
||||
const testing = @import("../../../testing.zig");
|
||||
|
||||
Reference in New Issue
Block a user