Skip to content

response.blob() drops body bytes — same shape as #227, needs Blob instance methods #234

Description

@TheHypnoo

Summary

Follow-up to #227. response.blob() (in crates/perry-stdlib/src/fetch.rs, immediately below the arrayBuffer() fix that landed via #232) has the same metadata-only-stub bug: resp.body is consumed only for .len(), then the resolved value is a 2-field stub object { size, type } with no actual byte storage. Any user code trying to read bytes out of a Blob sees nothing.

Why this is broader scope than #227

response.arrayBuffer() could be fixed by returning a real BufferHeader because the user-side consumers (new Uint8Array(buf) / Buffer.from(buf)) are already wired through the buffer registry. Blob is a distinct JS type with its own surface that needs to land first:

  • blob.arrayBuffer(): Promise<ArrayBuffer>
  • blob.text(): Promise<string>
  • blob.bytes(): Promise<Uint8Array> (newer, but increasingly common)
  • blob.slice(start?, end?, type?): Blob
  • blob.stream(): ReadableStream (separate gap; depends on stream impl)

Each method needs:

  1. A runtime symbol exported from perry-stdlib (probably keyed off a BLOB_REGISTRY similar to FETCH_RESPONSES).
  2. A codegen dispatch row in crates/perry-codegen/src/lower_call.rs routing blob.<method>() to the runtime symbol — mirroring how the arrayBuffer / clone / headers methods are routed for Response.

Repro

```ts
const res = await fetch("https://example.com/some.bin\");
const blob = await res.blob();
console.log("size:", blob.size, "type:", blob.type); // correct
const buf = await blob.arrayBuffer(); // currently undefined / no-op
const bytes = new Uint8Array(buf);
console.log("actual length:", bytes.length); // 0
```

Workaround in the meantime

Skip `blob()` entirely and call `response.arrayBuffer()` directly — that path now returns real bytes (#232).

Pointers

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions