decode = function (str) { var bytes = []; var done = false; spreadString(str).forEach(function(codePoint) { if(done) { throw Error("Base65536 sequence continued after final byte"); } var b1 = codePoint & ((possibleBytes) - 1); var blockStart = codePoint - b1; if(blockStart === paddingBlockStart) { bytes.push(b1); done = true; } else { var b2 = b2s[blockStart]; if(b2 === undefined) { throw Error("Not a valid Base65536 code point: " + String(codePoint)); } bytes.push(b1, b2); } }); return Buffer.from(bytes) }
...
var base65536 = require("base65536");
var buf = new Buffer("hello world"); // 11 bytes
var str = base65536.encode(buf);
console.log(str); // 6 code points, "驨ꍬ啯𒁷ꍲᕤ"
var buf2 = base65536.decode(str);
console.log(buf.equals(buf2)); // true
```
## API
### base65536.encode(buf)
...
encode = function (buf) { var codePoints = []; for(var i = 0; i < buf.length; i += 2) { var b1 = buf[i]; var blockStart = i + 1 < buf.length ? blockStarts[buf[i + 1]] : paddingBlockStart; var codePoint = blockStart + b1; codePoints.push(codePoint); } return codePoints.map(function(codePoint) { if(codePoint < bmpThreshold) { var first = codePoint; return String.fromCharCode(first); } // UTF-16 encode var first = high + ((codePoint - bmpThreshold) / offset); var second = low + (codePoint % offset); return String.fromCharCode(first) + String.fromCharCode(second); }).join(""); }
...
## Usage
```js
var base65536 = require("base65536");
var buf = new Buffer("hello world"); // 11 bytes
var str = base65536.encode(buf);
console.log(str); // 6 code points, "驨ꍬ啯𒁷ꍲᕤ"
var buf2 = base65536.decode(str);
console.log(buf.equals(buf2)); // true
```
## API
...