(buf, string, offset, length)
| 1127 | // ======================= |
| 1128 | |
| 1129 | function _hexWrite (buf, string, offset, length) { |
| 1130 | offset = Number(offset) || 0 |
| 1131 | var remaining = buf.length - offset |
| 1132 | if (!length) { |
| 1133 | length = remaining |
| 1134 | } else { |
| 1135 | length = Number(length) |
| 1136 | if (length > remaining) { |
| 1137 | length = remaining |
| 1138 | } |
| 1139 | } |
| 1140 | |
| 1141 | // must be an even number of digits |
| 1142 | var strLen = string.length |
| 1143 | assert(strLen % 2 === 0, 'Invalid hex string') |
| 1144 | |
| 1145 | if (length > strLen / 2) { |
| 1146 | length = strLen / 2 |
| 1147 | } |
| 1148 | for (var i = 0; i < length; i++) { |
| 1149 | var byte = parseInt(string.substr(i * 2, 2), 16) |
| 1150 | assert(!isNaN(byte), 'Invalid hex string') |
| 1151 | buf[offset + i] = byte |
| 1152 | } |
| 1153 | Buffer._charsWritten = i * 2 |
| 1154 | return i |
| 1155 | } |
| 1156 | |
| 1157 | function _utf8Write (buf, string, offset, length) { |
| 1158 | var charsWritten = Buffer._charsWritten = |
no test coverage detected