File tree 1 file changed +9
-9
lines changed
1 file changed +9
-9
lines changed Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ p._ensure = function(size) {
15
15
var remaining = this . buffer . length - this . offset ;
16
16
if ( remaining < size ) {
17
17
var oldBuffer = this . buffer ;
18
- this . buffer = Buffer ( oldBuffer . length + size ) ;
18
+ this . buffer = new Buffer ( oldBuffer . length + size ) ;
19
19
oldBuffer . copy ( this . buffer ) ;
20
20
}
21
21
}
@@ -40,20 +40,20 @@ p.addCString = function(string) {
40
40
//just write a 0 for empty or null strings
41
41
if ( ! string ) {
42
42
this . _ensure ( 1 ) ;
43
- this . buffer [ this . offset ++ ] = 0 ;
44
- return this ;
43
+ } else {
44
+ var len = Buffer . byteLength ( string ) ;
45
+ this . _ensure ( len + 1 ) ; //+1 for null terminator
46
+ this . buffer . write ( string , this . offset , len ) ;
47
+ this . offset += len ;
45
48
}
46
- var len = Buffer . byteLength ( string ) + 1 ;
47
- this . _ensure ( len ) ;
48
- this . buffer . write ( string , this . offset ) ;
49
- this . offset += len ;
50
- this . buffer [ this . offset ] = 0 ; //add null terminator
49
+
50
+ this . buffer [ this . offset ++ ] = 0 ; // null terminator
51
51
return this ;
52
52
}
53
53
54
54
p . addChar = function ( char ) {
55
55
this . _ensure ( 1 ) ;
56
- this . buffer . write ( char , this . offset ) ;
56
+ this . buffer . write ( char , this . offset , 1 ) ;
57
57
this . offset ++ ;
58
58
return this ;
59
59
}
You can’t perform that action at this time.
0 commit comments