@@ -13,7 +13,7 @@ const HeaderSize = 4;
13
13
class IOSDeviceLibStdioHandler extends EventEmitter {
14
14
constructor ( ) {
15
15
super ( ) ;
16
- this . _unfinishedMessage = new Buffer ( 0 ) ;
16
+ this . _unfinishedMessage = Buffer . alloc ( 0 ) ;
17
17
}
18
18
19
19
startReadingData ( ) {
@@ -57,12 +57,13 @@ class IOSDeviceLibStdioHandler extends EventEmitter {
57
57
// Get the message length header.
58
58
const messageSizeBuffer = data . slice ( 0 , HeaderSize ) ;
59
59
const messageLength = bufferpack . unpack ( ">i" , messageSizeBuffer ) [ 0 ] ;
60
+ const dataLengthWithoutHeader = data . length - HeaderSize ;
60
61
61
- if ( messageLength > data . length - HeaderSize ) {
62
+ if ( messageLength > dataLengthWithoutHeader ) {
62
63
// Less than one message in the buffer.
63
64
// Store the unfinished message untill the next call of the function.
64
65
this . _unfinishedMessage = data ;
65
- } else if ( data . length - 4 > messageLength ) {
66
+ } else if ( dataLengthWithoutHeader > messageLength ) {
66
67
// More than one message in the buffer.
67
68
const messageBuffer = this . _getMessageFromBuffer ( data , messageLength ) ;
68
69
@@ -82,7 +83,7 @@ class IOSDeviceLibStdioHandler extends EventEmitter {
82
83
const concatenatedMessage = Buffer . concat ( [ this . _unfinishedMessage , data ] ) ;
83
84
84
85
// Clear the unfinished message buffer.
85
- this . _unfinishedMessage = new Buffer ( 0 ) ;
86
+ this . _unfinishedMessage = Buffer . alloc ( 0 ) ;
86
87
this . _unpackMessages ( concatenatedMessage ) ;
87
88
} else {
88
89
// While debugging the data here contains one character - \0, null or 0.
0 commit comments