mirror of
https://github.com/denoland/deno.git
synced 2024-11-25 15:29:32 -05:00
refactor(websocket): use ZeroCopyBuf to return binary data (#10446)
This commit is contained in:
parent
fc9c7de94b
commit
6804b2f889
2 changed files with 4 additions and 7 deletions
|
@ -326,9 +326,9 @@
|
|||
let data;
|
||||
|
||||
if (this.binaryType === "blob") {
|
||||
data = new Blob([new Uint8Array(value)]);
|
||||
data = new Blob([value]);
|
||||
} else {
|
||||
data = new Uint8Array(value).buffer;
|
||||
data = value.buffer;
|
||||
}
|
||||
|
||||
const event = new MessageEvent("message", {
|
||||
|
|
|
@ -289,7 +289,7 @@ pub async fn op_ws_close(
|
|||
#[serde(tag = "kind", content = "value", rename_all = "camelCase")]
|
||||
pub enum NextEventResponse {
|
||||
String(String),
|
||||
Binary(Vec<u8>),
|
||||
Binary(ZeroCopyBuf),
|
||||
Close { code: u16, reason: String },
|
||||
Ping,
|
||||
Pong,
|
||||
|
@ -313,10 +313,7 @@ pub async fn op_ws_next_event(
|
|||
let val = rx.next().or_cancel(cancel).await?;
|
||||
let res = match val {
|
||||
Some(Ok(Message::Text(text))) => NextEventResponse::String(text),
|
||||
Some(Ok(Message::Binary(data))) => {
|
||||
// TODO(ry): don't use json to send binary data.
|
||||
NextEventResponse::Binary(data)
|
||||
}
|
||||
Some(Ok(Message::Binary(data))) => NextEventResponse::Binary(data.into()),
|
||||
Some(Ok(Message::Close(Some(frame)))) => NextEventResponse::Close {
|
||||
code: frame.code.into(),
|
||||
reason: frame.reason.to_string(),
|
||||
|
|
Loading…
Reference in a new issue