Bytes.toString now offers something reprish; fromUtf8 does what toString used to do

This commit is contained in:
Tony Garnock-Jones 2019-06-07 13:13:38 +01:00
parent 65866b9041
commit 5d9b03171d
3 changed files with 9 additions and 5 deletions

View File

@ -1,6 +1,6 @@
{
"name": "preserves",
"version": "0.0.8",
"version": "0.0.9",
"description": "Experimental data serialization format",
"homepage": "https://gitlab.com/tonyg/preserves",
"license": "MIT",

View File

@ -112,9 +112,9 @@ class Decoder {
decodebinary(minor, bs) {
switch (minor) {
case 0: return this.decodeint(bs._view);
case 1: return bs.toString();
case 1: return bs.fromUtf8();
case 2: return bs;
case 3: return Symbol.for(bs.toString());
case 3: return Symbol.for(bs.fromUtf8());
}
}

View File

@ -240,14 +240,18 @@ Bytes.decodeUtf8 = function (bs) {
return decoder.decode(underlying(bs));
};
Bytes.prototype.toString = function () {
Bytes.prototype.fromUtf8 = function () {
return decoder.decode(this._view);
};
Bytes.prototype[util.inspect.custom] = function (depth, options) {
Bytes.prototype.toString = function () {
return '#"' + this.__asciify() + '"';
};
Bytes.prototype[util.inspect.custom] = function (depth, options) {
return this.toString();
};
Bytes.prototype.__asciify = function () {
const pieces = [];
const v = this._view;