Skip to content

Support 32-bit architecture in stream #403

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 2 commits into from
Apr 10, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions packages/client-node/src/utils/stream.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import Stream from 'stream'
import { constants } from 'buffer'

// See https://github.com/v8/v8/commit/ea56bf5513d0cbd2a35a9035c5c2996272b8b728
const MaxStringLength = Math.pow(2, 29) - 24
const { MAX_STRING_LENGTH } = constants

export function isStream(obj: any): obj is Stream.Readable {
return obj !== null && typeof obj.pipe === 'function'
export function isStream(obj: unknown): obj is Stream.Readable {
return (
typeof obj === 'object' &&
obj !== null &&
'pipe' in obj &&
typeof obj.pipe === 'function' &&
'on' in obj &&
typeof obj.on === 'function'
)
}

export async function getAsText(stream: Stream.Readable): Promise<string> {
@@ -13,10 +20,10 @@ export async function getAsText(stream: Stream.Readable): Promise<string> {
const textDecoder = new TextDecoder()
for await (const chunk of stream) {
const decoded = textDecoder.decode(chunk, { stream: true })
if (decoded.length + text.length > MaxStringLength) {
if (decoded.length + text.length > MAX_STRING_LENGTH) {
throw new Error(
'The response length exceeds the maximum allowed size of V8 String: ' +
`${MaxStringLength}; consider limiting the amount of requested rows.`,
`${MAX_STRING_LENGTH}; consider limiting the amount of requested rows.`,
)
}
text += decoded
Loading