Skip to content

Commit a4b7a93

Browse files
committed
provides a temporary fix for #110
Signed-off-by: Oleh Dokuka <[email protected]> Signed-off-by: Oleh Dokuka <[email protected]> Signed-off-by: Oleh Dokuka <[email protected]>
1 parent c271a37 commit a4b7a93

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

packages/rsocket-core/src/LiteBuffer.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
import type {Buffer as NodeBuffer} from 'buffer';
55
import ExistingBufferModule from 'buffer';
66

7-
const bufferExists =
7+
const hasGlobalBuffer =
88
typeof global !== 'undefined' && global.hasOwnProperty('Buffer');
9+
const hasBufferModule = ExistingBufferModule.hasOwnProperty('Buffer');
910

1011
function notImplemented(msg?: string): void {
1112
const message = msg ? `Not implemented: ${msg}` : 'Not implemented';
@@ -604,7 +605,10 @@ export class Buffer extends Uint8Array {
604605
* Returns true if obj is a Buffer, false otherwise.
605606
*/
606607
static isBuffer(obj: any): boolean {
607-
return isInstance(obj, Buffer);
608+
return (
609+
isInstance(obj, Buffer) ||
610+
(!hasGlobalBuffer && hasBufferModule && isInstance(obj, Uint8Array))
611+
);
608612
}
609613

610614
static isEncoding(encoding: any): boolean {
@@ -991,8 +995,8 @@ export class Buffer extends Uint8Array {
991995
}
992996
}
993997

994-
if (!bufferExists) {
995-
if (ExistingBufferModule.hasOwnProperty('Buffer')) {
998+
if (!hasGlobalBuffer) {
999+
if (hasBufferModule) {
9961000
// ExistingBuffer is likely to be a polyfill, hence we can override it
9971001
// eslint-disable-next-line no-undef
9981002
// $FlowFixMe
@@ -1012,4 +1016,4 @@ if (!bufferExists) {
10121016
});
10131017
}
10141018

1015-
export const LiteBuffer: NodeBuffer = bufferExists ? global.Buffer : Buffer;
1019+
export const LiteBuffer: NodeBuffer = hasGlobalBuffer ? global.Buffer : Buffer;

packages/rsocket-tcp-client/src/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717

1818
'use strict';
1919

20-
import {RSocketTcpClient, RSocketTcpConnection, RSocketTlsClient} from './RSocketTcpClient';
20+
import {
21+
RSocketTcpClient,
22+
RSocketTcpConnection,
23+
RSocketTlsClient,
24+
} from './RSocketTcpClient';
2125
export default RSocketTcpClient;
2226
export {RSocketTcpConnection, RSocketTlsClient};

0 commit comments

Comments
 (0)