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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support send TypedArray objects #4715

Closed
2 tasks done
suerta-git opened this issue Apr 28, 2023 · 8 comments
Closed
2 tasks done

Support send TypedArray objects #4715

suerta-git opened this issue Apr 28, 2023 · 8 comments
Labels
feature request New feature to be added good first issue Good for newcomers

Comments

@suerta-git
Copy link

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the feature has not already been requested

馃殌 Feature Proposal

AFAIK, currently only node.js Buffer objects are accepted to be sent by reply.send() method for buffer-like data.

However, as a part of ECMAScript standard, TypedArray and its subclasses are also commonly used, because they are well supported by both of browser and node. So support them is obviously necessary.

Motivation

No response

Example

No response

@jsumners
Copy link
Member

What are you expecting to happen? Buffers are sent as an octet stream:

fastify/lib/reply.js

Lines 151 to 157 in 7431a23

if (Buffer.isBuffer(payload)) {
if (hasContentType === false) {
this[kReplyHeaders]['content-type'] = CONTENT_TYPE.OCTET
}
onSendHook(this, payload)
return this
}

A TypedArray could be sent in the same way, but the receiving client would not be receiving an instance of TypedArray.

@suerta-git
Copy link
Author

Sorry @jsumners, I don't understand what the conflict is between octet-stream and TypedArray.

In my mind, Buffers and TypedArrays are just different ways under different environments to manipulate binary data. Both of them can do the same thing on any piece of binary data.
As for octet-stream, it is just a content type hint that indicates the response data is binary, not related to any specific type or class.

@jsumners
Copy link
Member

I didn't say there is a conflict. I asked what you expect to happen when reply.send(aTypedArry) is performed.

@suerta-git
Copy link
Author

Ok, I misunderstood.

I asked what you expect to happen when reply.send(aTypedArry) is performed.

As same as buffers I think. Send bytes to client.

@jsumners
Copy link
Member

Then I have already highlighted where a change needs to be made, and what needs to be done. A PR would be welcome.

@Eomm Eomm added feature request New feature to be added good first issue Good for newcomers labels Apr 28, 2023
@Eomm
Copy link
Member

Eomm commented Apr 28, 2023

Totally agree!

The new aws@3 client use them a lot!

Eomm pushed a commit that referenced this issue May 10, 2023
* add support for TypedArray in Reply.send

* add TypedArray section to Reply.send doc

* fix typedarray test to use sget

* fix TypedArray doc section

* fix code duplication

* fix test to use fastify inject
@voxpelli
Copy link
Contributor

voxpelli commented Jul 3, 2023

Fixed by #4735, right?

@metcoder95
Copy link
Member

Done by #4735

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature to be added good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

5 participants