Skip to content

Transfered (PostMessaged) disk- blob's aren't readable #47334

Description

@jimmywarting

I notice that blobs transfered over workers aren't readable at all.

  • it only applies to blobs coming from fs.openAsBlob
  • in-memory constructed blobs works fine.

mini repro:

import { Worker } from 'worker_threads'
const worker = new Worker('./worker.js')
worker.once('message', blob => {
  // worker.terminate() // Should be fine to do this as well
  blob.text()
})
// worker.js
import { parentPort } from 'node:worker_threads'
import { openAsBlob } from 'node:fs'

const blob = await openAsBlob(import.meta.url.slice(7)) // file:// doesn't work
parentPort.postMessage(blob)

I would assume that if you also closed the worker it would still work just fine to read the blob, even if it came from another thread...

originally posted by @jimmywarting in #45258 (comment)

maybe also worth trying out to write a test that also use MessageChannel?
...haven't tested if MessageChannel works or not.

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

    fsIssues and PRs related to file-system APIs and the fs module.workerIssues and PRs related to the worker_threads module and Worker API.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions