@stricahq/cbors
Version:
cbor encoder and decoder with annotation
32 lines (31 loc) • 797 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const buffer_1 = require("buffer");
class BufferList {
constructor() {
this.buf = buffer_1.Buffer.alloc(0);
}
get length() {
return this.buf.length;
}
read(n) {
if (n === 0) {
return buffer_1.Buffer.alloc(0);
}
if (n < 0) {
throw new Error('invalid length');
}
const chunk = this.buf.slice(0, n);
this.buf = this.buf.slice(n);
if (chunk.length < n) {
throw new Error('Not enough buffer');
}
return chunk;
}
push(chunk) {
if (!chunk.length)
return;
this.buf = buffer_1.Buffer.concat([this.buf, chunk]);
}
}
exports.default = BufferList;