mirror of
https://github.com/danbulant/node-x11
synced 2026-05-20 04:48:56 +00:00
allow Buffer to be used as 'a' format pack parameter
This commit is contained in:
parent
7a2761b061
commit
aa5c4bac1c
1 changed files with 11 additions and 4 deletions
|
|
@ -244,6 +244,7 @@ UnpackStream.prototype.pack = function(format, arguments)
|
|||
var n = arguments[arg++];
|
||||
buf[offset++] = n;
|
||||
break;
|
||||
case 's': // TODO: implement signed INT16!!!
|
||||
case 'S':
|
||||
var n = arguments[arg++];
|
||||
buf[offset++] = n & 0xff;
|
||||
|
|
@ -256,11 +257,17 @@ UnpackStream.prototype.pack = function(format, arguments)
|
|||
buf[offset++] = (n >> 16) & 0xff;
|
||||
buf[offset++] = (n >> 24) & 0xff;
|
||||
break;
|
||||
case 'a': // string
|
||||
case 'a': // string or buffer
|
||||
var str = arguments[arg++];
|
||||
// TODO: buffer.write could be faster
|
||||
for (var c = 0; c < str.length; ++c)
|
||||
buf[offset++] = str.charCodeAt(c);
|
||||
if (Buffer.isBuffer(str))
|
||||
{
|
||||
str.copy(buf, offset);
|
||||
offset += str.length;
|
||||
} else {
|
||||
// TODO: buffer.write could be faster
|
||||
for (var c = 0; c < str.length; ++c)
|
||||
buf[offset++] = str.charCodeAt(c);
|
||||
}
|
||||
break;
|
||||
case 'p': // padded string
|
||||
var str = arguments[arg++];
|
||||
|
|
|
|||
Loading…
Reference in a new issue