tessel / t1-runtime

[UNMAINTAINED] Tessel 1 JavaScript runtime.
Other
117 stars 33 forks source link

`Buffer#fill` with string instead of number #659

Closed LinusU closed 10 years ago

LinusU commented 10 years ago

Buffer#fill silently fails when given a string as the first parameter.

Tessel

> a = new Buffer(4)
<Buffer 00 00 00 00>
> a.fill('=')
undefined
> a
<Buffer 00 00 00 00>

Node.js

> a = new Buffer(4)
<Buffer 39 67 81 a3>
> a.fill('=')
undefined
> a
<Buffer 3d 3d 3d 3d>

(Note that node.js dosen't always return a zero-filled buffer which is correct behaviour)

Previous versions of node.js only used the first character of the string (.charCodeAt(0)). It has now been updated to use the entire string when filling. Hopefully we can get the tessel to support more than one character.

I might have dreamed this, it's not in 0.10.x, I haven't installed 0.11.x yet and I didn't find it thru a quick skim of the source (why is fill the only function not defined in lib/buffer.js?). A first implementation could use .charCodeAt(0), that would make it a really quick fix.

fill with string used in official tests: https://github.com/joyent/node/blob/857975d5e7e0d7bf38577db0478d9e5ede79922e/test/simple/test-buffer-inspect.js#L32

fill implementation in node.js: https://github.com/joyent/node/blob/master/src/node_buffer.cc#L360

LinusU commented 10 years ago

@johnnyman727 Do you want to keep this open until we merge #672? Otherwise I think we can close it since #671 got merged...

johnnyman727 commented 10 years ago

Nah we can close this for now. Thanks!