Skip to content

Commit 672af99

Browse files
committed
feat(connection): allow sending "Buffer" in "writeText" method
1 parent 84704b5 commit 672af99

File tree

4 files changed

+8
-3
lines changed

4 files changed

+8
-3
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## v0.2.4
44

55
- feat(connection): added option `forceNewConnection` for connection creation.
6+
- feat(connection): allow sending `Buffer` in `writeText` method.
67

78
## v0.2.3
89

src/examples/http/client.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ function writeLog(msg: string): void {
3838

3939
cli.setMasking(false);
4040
cli.writeText('hello world');
41+
cli.writeText(Buffer.from('hello world (buffer)'));
4142
cli.on('message', (msg) => {
4243

4344
if (msg.mode !== $WS.EFrameReceiveMode.STANDARD) {

src/lib/AbstractConnection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ export abstract class AbstractWsConnection extends $Events.EventEmitter implemen
162162
}
163163

164164
public writeText(
165-
data: string | string[],
165+
data: Buffer | string | Array<Buffer | string>,
166166
cb: D.IErrorCallback = this._defaultWriteCallback,
167167
): boolean {
168168

src/lib/Decl.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -474,9 +474,12 @@ export interface IWebSocket {
474474
/**
475475
* Send a text message to remote-side, in a single TEXT message.
476476
*
477-
* > Return true if the data is flushed to kernel buffer completely, otherwise false.
477+
* @throws `E_CONN_LOST` will be thrown if the connection is closed.
478+
* @throws `E_CONN_READONLY` will be thrown if the connection is not writable (half-closed).
479+
*
480+
* @returns true if the data is flushed to kernel buffer completely, otherwise false.
478481
*/
479-
writeText(data: string | string[], callback?: IErrorCallback): boolean;
482+
writeText(data: Buffer | string | Array<Buffer | string>, callback?: IErrorCallback): boolean;
480483

481484
/**
482485
* Send a binary message to remote-side, in a single BINARY message.

0 commit comments

Comments
 (0)