| 4596 | } |
| 4597 | |
| 4598 | function bufferSplit(buf, chr) { |
| 4599 | assert.buffer(buf); |
| 4600 | assert.string(chr); |
| 4601 | |
| 4602 | var parts = []; |
| 4603 | var lastPart = 0; |
| 4604 | var matches = 0; |
| 4605 | for (var i = 0; i < buf.length; ++i) { |
| 4606 | if (buf[i] === chr.charCodeAt(matches)) |
| 4607 | ++matches; |
| 4608 | else if (buf[i] === chr.charCodeAt(0)) |
| 4609 | matches = 1; |
| 4610 | else |
| 4611 | matches = 0; |
| 4612 | |
| 4613 | if (matches >= chr.length) { |
| 4614 | var newPart = i + 1; |
| 4615 | parts.push(buf.slice(lastPart, newPart - matches)); |
| 4616 | lastPart = newPart; |
| 4617 | matches = 0; |
| 4618 | } |
| 4619 | } |
| 4620 | if (lastPart <= buf.length) |
| 4621 | parts.push(buf.slice(lastPart, buf.length)); |
| 4622 | |
| 4623 | return (parts); |
| 4624 | } |
| 4625 | |
| 4626 | function ecNormalize(buf, addZero) { |
| 4627 | assert.buffer(buf); |