Skip to content

Commit

Permalink
to-string numbers written to the stream
Browse files Browse the repository at this point in the history
  • Loading branch information
mafintosh committed Sep 1, 2016
1 parent 4ca83d6 commit 3e285ba
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
15 changes: 11 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ function isArrayish (arr) {
return /Array\]$/.test(Object.prototype.toString.call(arr))
}

function isBufferish (p) {
return typeof p === 'string' || isArrayish(p) || (p && typeof p.subarray === 'function')
}

function stringConcat (parts) {
var strings = []
var needsToString = false
Expand All @@ -82,8 +86,10 @@ function stringConcat (parts) {
strings.push(p)
} else if (Buffer.isBuffer(p)) {
strings.push(p)
} else {
} else if (isBufferish(p)) {
strings.push(new Buffer(p))
} else {
strings.push(new Buffer(String(p)))
}
}
if (Buffer.isBuffer(parts[0])) {
Expand All @@ -101,10 +107,11 @@ function bufferConcat (parts) {
var p = parts[i]
if (Buffer.isBuffer(p)) {
bufs.push(p)
} else if (typeof p === 'string' || isArrayish(p)
|| (p && typeof p.subarray === 'function')) {
} else if (isBufferish(p)) {
bufs.push(new Buffer(p))
} else bufs.push(new Buffer(String(p)))
} else {
bufs.push(new Buffer(String(p)))
}
}
return Buffer.concat(bufs)
}
Expand Down
13 changes: 12 additions & 1 deletion test/string.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ test('string from buffers with multibyte characters', function (t) {
var snowman = new Buffer('☃')
for (var i = 0; i < 8; i++) {
strings.write(snowman.slice(0, 1))
strings.write(snowman.slice(1))
strings.write(snowman.slice(1))
}
strings.end()
})
Expand All @@ -74,3 +74,14 @@ test('string infer encoding with empty string chunk', function (t) {
strings.write("dogs")
strings.end()
})

test('to string numbers', function (t) {
var write = concat(function (str) {
t.equal(str, 'a1000')
t.end()
})

write.write('a')
write.write(1000)
write.end()
})

3 comments on commit 3e285ba

@ChALkeR
Copy link

@ChALkeR ChALkeR commented on 3e285ba Sep 1, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was filed as a public report and was disclosed but not fixed for 13 days?
I sent a private report for a reason, not sure why this was handled this way.

Btw, @maxogden, what about 1.4.x?

@max-mapper
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was filed as a public report and was disclosed but not fixed for 13 days?
I sent a private report for a reason, not sure why this was handled this way.

screen shot 2016-09-01 at 5 32 29 pm

@ChALkeR
Copy link

@ChALkeR ChALkeR commented on 3e285ba Sep 2, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maxogden Sorry, I don't understand what you mean by that picture, but I assume that you think that I am talking about the speed of fixing this issue. I am not.

What I am talking about is the fact that I sent a private report, then, as a result of that, the issue has been made public, and was kept disclosed but unfixed for 13 days.

Correct me if I am wrong, please.

Please sign in to comment.