Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TRI-4135] Add support for Blob in payloads and outputs. #1523

Open
matt-aitken opened this issue Dec 2, 2024 · 1 comment
Open

[TRI-4135] Add support for Blob in payloads and outputs. #1523

matt-aitken opened this issue Dec 2, 2024 · 1 comment

Comments

@matt-aitken
Copy link
Member

matt-aitken commented Dec 2, 2024

We use SuperJSON so you can use types beyond regular JSON in your payloads/outputs. It would be great to add Blob to this.

The source code is here:

superjson.registerCustom<Buffer, number[]>(

TRI-4135

@matt-aitken matt-aitken changed the title Add support for Blob in payloads and outputs. [TRI-4135] Add support for Blob in payloads and outputs. Dec 2, 2024
@SjxSubham SjxSubham mentioned this issue Dec 2, 2024
3 tasks
@chandraguptgosavi
Copy link

@matt-aitken here's what I tried for adding Blob to SuperJSON

superjson.registerCustom<Blob, number[]>(
    {
      isApplicable: (v): v is Blob => typeof Blob === "function" && v instanceof Blob,
      serialize: async (v) => {
        const arrayBuffer = await v.arrayBuffer();
        return [...(new Uint8Array(arrayBuffer))];
      },
      deserialize: (v) => {
        const u8Array = new Uint8Array(v);
        const arrayBuffer = u8Array.buffer.slice(u8Array.byteOffset, u8Array.byteOffset + u8Array.byteLength);
        return new Blob([arrayBuffer]);
      },
    },
    "blob"
  );

but unfortunately serialize function cannot return promise and Blob cannot be serialized synchronously.
Would you consider other approach for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants