diff options
author | 2023-05-22 11:46:28 -0700 | |
---|---|---|
committer | 2023-05-22 11:46:39 -0700 | |
commit | a5acf7bfa0333fc5cb298df2b3ea09eaa56075ac (patch) | |
tree | 94277814b5229d03f10a1e2dd7d2541265482b58 /src/bun.js/api/server.zig | |
parent | 3de350b24dbae7512b5afd71c1e566137390bf08 (diff) | |
download | bun-a5acf7bfa0333fc5cb298df2b3ea09eaa56075ac.tar.gz bun-a5acf7bfa0333fc5cb298df2b3ea09eaa56075ac.tar.zst bun-a5acf7bfa0333fc5cb298df2b3ea09eaa56075ac.zip |
[ServerWebSocket] `binaryType` now defaults to `"nodebuffer"`
Previously, this defaulted to "uint8array", so this shouldn't be a breaking change unless you make use of `.slice()` in which case it will now be a reference to the same ArrayBuffer rather than a clone.
The rationale for this change is most usages of Uint8Array on the server need a little more than just the bytes. Many npm packages expect Buffer rather than Uint8Array. Directly returning it for binary websocket messages is faster than creating another one.
Diffstat (limited to 'src/bun.js/api/server.zig')
-rw-r--r-- | src/bun.js/api/server.zig | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/bun.js/api/server.zig b/src/bun.js/api/server.zig index 59410d0cb..2ce7347c0 100644 --- a/src/bun.js/api/server.zig +++ b/src/bun.js/api/server.zig @@ -3256,7 +3256,7 @@ pub const ServerWebSocket = struct { this_value: JSValue = .zero, websocket: uws.AnyWebSocket = undefined, closed: bool = false, - binary_type: JSC.BinaryType = .Uint8Array, + binary_type: JSC.BinaryType = .Buffer, opened: bool = false, pub usingnamespace JSC.Codegen.JSServerWebSocket; @@ -3355,17 +3355,17 @@ pub const ServerWebSocket = struct { str.markUTF8(); break :brk str.toValueGC(globalObject); }, - .binary => if (this.binary_type == .Uint8Array) + .binary => if (this.binary_type == .Buffer) JSC.ArrayBuffer.create( globalObject, message, - .Uint8Array, + .Buffer, ) - else if (this.binary_type == .Buffer) + else if (this.binary_type == .Uint8Array) JSC.ArrayBuffer.create( globalObject, message, - .Buffer, + .Uint8Array, ) else JSC.ArrayBuffer.create( |