Skip to content

Support binary data #164

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

Merged
merged 5 commits into from
Feb 1, 2024
Merged

Support binary data #164

merged 5 commits into from
Feb 1, 2024

Conversation

mattrobenolt
Copy link
Member

@mattrobenolt mattrobenolt commented Jan 31, 2024

This handles better for BLOB type columns. Without this, it basically would have only worked for ASCII binary data since it gets Buffer.toString()'d, but then does an extra quoting and sanitization pass.

For binary data, which we can assume is coming from a Uint8Array, we want to send as hexadecimal.

Fixes #161

This handles better for BLOB type columns. Without this, it basically
would have only worked for ASCII binary data since it gets
Buffer.toString()'d, but then does an extra quoting and sanitization
pass.

For binary data, which we can assume is coming from a Buffer, we want to
send as hexadecimal.

Fixes #161
@mattrobenolt mattrobenolt requested a review from ayrton January 31, 2024 20:15
@mattrobenolt
Copy link
Member Author

Ok, the fundamental issue with this solution is that Buffer is specific to node and doesn't exist for all JS runtimes.

I think we need to do something to deal with this as an ArrayBuffer or Uint8Array ?

I'm not sure if we can feature-detect and allow Buffer when that's available globally or not.

@ayrton ayrton force-pushed the sanitize-buffer branch 2 times, most recently from 81daa57 to 8d0ba85 Compare January 31, 2024 22:18
@mattrobenolt mattrobenolt changed the title Encode a Buffer as hexadecimal Encode a Uint8Array as hexadecimal Jan 31, 2024
@mattrobenolt mattrobenolt marked this pull request as ready for review February 1, 2024 00:15
@mattrobenolt
Copy link
Member Author

We should be able to add some trivial unit tests for this to confirm behavior.

@ayrton ayrton changed the title Encode a Uint8Array as hexadecimal Support binary data Feb 1, 2024
@@ -379,7 +379,7 @@ function decodeRow(row: QueryResultRow): Array<string | null> {
}

export function cast(field: Field, value: string | null): any {
if (value === '' || value == null) {
if (value == null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we want to handle empty strings when it's binary data and not just return an empty string

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, see my comment below.

@@ -379,7 +379,7 @@ function decodeRow(row: QueryResultRow): Array<string | null> {
}

export function cast(field: Field, value: string | null): any {
if (value === '' || value == null) {
if (value == null) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, see my comment below.

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 this pull request may close these issues.

bug: BLOB / Buffer input parameters result in corrupted data
3 participants