Skip to content

Blob.stream() concatenates all chunks into a single chunk instead of separate Uint8Arrays #28762

@kevgeoleo

Description

@kevgeoleo

What version of Bun is running?

1.3.11-canary.1+9e93bfa1b

What platform is your computer?

Linux 5.10.0-12-amd64 x86_64 x86_64

What steps can reproduce the bug?

Hi,

I would like to report a behavior in Bun that can be reproduced using the below snippet

async function main () {
  const blob = new Blob([
    new Uint8Array([
       58, 162, 101, 114, 111, 111, 116, 115, 129, 216,  42,
       88,  37,   0,   1,  85,  18,  32,  95, 102, 197,  19,
      218,  30, 103,  78, 133, 139,  57, 105,  28,  11,   0,
      246, 124, 167,  41, 140, 239, 220, 248, 168, 136,  35,
      196,  72, 236, 184, 232,  89, 103, 118, 101, 114, 115,
      105, 111, 110,   1
    ]),
    new Uint8Array([ 68 ]),
    new Uint8Array([
        1,  85,  18,  32,  95, 102, 197,  19,
      218,  30, 103,  78, 133, 139,  57, 105,
       28,  11,   0, 246, 124, 167,  41, 140,
      239, 220, 248, 168, 136,  35, 196,  72,
      236, 184, 232,  89
    ]),
    new Uint8Array([
       90, 189, 174, 145, 144, 134, 214,
      117,  47, 251, 231, 254,  29, 238,
        0,  29, 212, 201, 123, 107,  95,
      130,  24, 168, 207, 139, 134, 177,
      187,  88, 167,  36
    ])
  ])

  await blob.stream().pipeTo(new WritableStream({
    write (chunk) {
      console.log(chunk)
    }
  }))
}

main().then(() => console.log('done')).catch(console.error)

What is the expected behavior?

Output in separate Blobs

root@KContainer:~/48916# node blob-stream-bug.mjs
Uint8Array(59) [
   58, 162, 101, 114, 111, 111, 116, 115, 129, 216,  42,
   88,  37,   0,   1,  85,  18,  32,  95, 102, 197,  19,
  218,  30, 103,  78, 133, 139,  57, 105,  28,  11,   0,
  246, 124, 167,  41, 140, 239, 220, 248, 168, 136,  35,
  196,  72, 236, 184, 232,  89, 103, 118, 101, 114, 115,
  105, 111, 110,   1
]
Uint8Array(1) [ 68 ]
Uint8Array(36) [
    1,  85,  18,  32,  95, 102, 197,  19,
  218,  30, 103,  78, 133, 139,  57, 105,
   28,  11,   0, 246, 124, 167,  41, 140,
  239, 220, 248, 168, 136,  35, 196,  72,
  236, 184, 232,  89
]
Uint8Array(32) [
   90, 189, 174, 145, 144, 134, 214,
  117,  47, 251, 231, 254,  29, 238,
    0,  29, 212, 201, 123, 107,  95,
  130,  24, 168, 207, 139, 134, 177,
  187,  88, 167,  36
]
done

What do you see instead?

root@KContainer:~/48916# bun run blob-stream-bug.mjs
Uint8Array(128) [ 58, 162, 101, 114, 111, 111, 116, 115, 129, 216, 42, 88, 37, 0, 1, 85, 18, 32, 95, 102, 197, 19, 218, 30, 103, 78, 133, 139, 57, 105, 28, 11, 0, 246, 124, 167, 41, 140, 239, 220, 248, 168, 136, 35, 196, 72, 236, 184, 232, 89, 103, 118, 101, 114, 115, 105, 111, 110, 1, 68, 1, 85, 18, 32, 95, 102, 197, 19, 218, 30, 103, 78, 133, 139, 57, 105, 28, 11, 0, 246, 124, 167, 41, 140, 239, 220, 248, 168, 136, 35, 196, 72, 236, 184, 232, 89, 90, 189, 174, 145, 144, 134, 214, 117, 47, 251, 231, 254, 29, 238, 0, 29, 212, 201, 123, 107, 95, 130, 24, 168, 207, 139, 134, 177, 187, 88, 167, 36 ]
done

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions