File tree 2 files changed +23
-5
lines changed
2 files changed +23
-5
lines changed Original file line number Diff line number Diff line change @@ -73,6 +73,10 @@ function isArrayish (arr) {
73
73
return / A r r a y \] $ / . test ( Object . prototype . toString . call ( arr ) )
74
74
}
75
75
76
+ function isBufferish ( p ) {
77
+ return typeof p === 'string' || isArrayish ( p ) || ( p && typeof p . subarray === 'function' )
78
+ }
79
+
76
80
function stringConcat ( parts ) {
77
81
var strings = [ ]
78
82
var needsToString = false
@@ -82,8 +86,10 @@ function stringConcat (parts) {
82
86
strings . push ( p )
83
87
} else if ( Buffer . isBuffer ( p ) ) {
84
88
strings . push ( p )
85
- } else {
89
+ } else if ( isBufferish ( p ) ) {
86
90
strings . push ( new Buffer ( p ) )
91
+ } else {
92
+ strings . push ( new Buffer ( String ( p ) ) )
87
93
}
88
94
}
89
95
if ( Buffer . isBuffer ( parts [ 0 ] ) ) {
@@ -101,10 +107,11 @@ function bufferConcat (parts) {
101
107
var p = parts [ i ]
102
108
if ( Buffer . isBuffer ( p ) ) {
103
109
bufs . push ( p )
104
- } else if ( typeof p === 'string' || isArrayish ( p )
105
- || ( p && typeof p . subarray === 'function' ) ) {
110
+ } else if ( isBufferish ( p ) ) {
106
111
bufs . push ( new Buffer ( p ) )
107
- } else bufs . push ( new Buffer ( String ( p ) ) )
112
+ } else {
113
+ bufs . push ( new Buffer ( String ( p ) ) )
114
+ }
108
115
}
109
116
return Buffer . concat ( bufs )
110
117
}
Original file line number Diff line number Diff line change @@ -58,7 +58,7 @@ test('string from buffers with multibyte characters', function (t) {
58
58
var snowman = new Buffer ( '☃' )
59
59
for ( var i = 0 ; i < 8 ; i ++ ) {
60
60
strings . write ( snowman . slice ( 0 , 1 ) )
61
- strings . write ( snowman . slice ( 1 ) )
61
+ strings . write ( snowman . slice ( 1 ) )
62
62
}
63
63
strings . end ( )
64
64
} )
@@ -74,3 +74,14 @@ test('string infer encoding with empty string chunk', function (t) {
74
74
strings . write ( "dogs" )
75
75
strings . end ( )
76
76
} )
77
+
78
+ test ( 'to string numbers' , function ( t ) {
79
+ var write = concat ( function ( str ) {
80
+ t . equal ( str , 'a1000' )
81
+ t . end ( )
82
+ } )
83
+
84
+ write . write ( 'a' )
85
+ write . write ( 1000 )
86
+ write . end ( )
87
+ } )
You can’t perform that action at this time.
0 commit comments