Skip to content

Commit

Permalink
fix(websocket): prevent sending entire buffer when streaming Uint8Arr…
Browse files Browse the repository at this point in the history
…ay chunks (#3570)

* fix(websocket): prevent full buffer send on Uint8Array chunks

* Fix formatting and line endings for CI compliance
  • Loading branch information
Ariel-Moroshko authored Oct 29, 2024
1 parent a90db7c commit 745c291
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/helper/websocket/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ describe('WSContext', () => {
expect(nullURLWS.url).toBeNull()
})
it('Should normalize message in send()', () => {
let data: string | ArrayBuffer | null = null
let data: string | ArrayBuffer | Uint8Array | null = null
const wsContext = new WSContext({
// eslint-disable-next-line @typescript-eslint/no-unused-vars
send(received, _options) {
Expand All @@ -104,6 +104,6 @@ describe('WSContext', () => {
expect(data).toBeInstanceOf(ArrayBuffer)

wsContext.send(new Uint8Array(16))
expect(data).toBeInstanceOf(ArrayBuffer)
expect(data).toBeInstanceOf(Uint8Array)
})
})
5 changes: 1 addition & 4 deletions src/helper/websocket/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,7 @@ export class WSContext<T = unknown> {
this.protocol = init.protocol ?? null
}
send(source: string | ArrayBuffer | Uint8Array, options?: SendOptions): void {
this.#init.send(
typeof source === 'string' ? source : source instanceof Uint8Array ? source.buffer : source,
options ?? {}
)
this.#init.send(source, options ?? {})
}
raw?: T
binaryType: BinaryType = 'arraybuffer'
Expand Down

0 comments on commit 745c291

Please sign in to comment.