当我使用带缓冲区的快速服务器时,我遇到错误,它在此行崩溃:
authorization = Buffer.from(authorization, 'base64').toString('utf8')
错误消息是:
TypeError:
Object function Buffer(subject, encoding, offset) { if (!(this instanceof Buffer)) { return new Buffer(subject, encoding, offset); } var type; if (typeof offset === 'number') { if (!Buffer.isBuffer(subject)) { throw new TypeError('First argument must be a Buffer when slicing'); } this.length = +encoding > 0 ? Math.ceil(encoding) : 0; this.parent = subject.parent ? subject.parent : subject; this.offset = offset; } else { switch (type = typeof subject) { case 'number': this.length = +subject > 0 ? Math.ceil(subject) : 0; break; case 'string': this.length = Buffer.byteLength(subject, encoding); break; case 'object': this.length = +subject.length > 0 ? Math.ceil(subject.length) : 0; break; default: throw new TypeError('First argument needs to be a number, ' + 'array or string.'); } if (this.length > Buffer.poolSize) {this.parent = new SlowBuffer(this.length); this.offset = 0; } else if (this.length > 0) { if (!pool || pool.length - pool.used < this.length) allocPool(); this.parent = pool; this.offset = pool.used; pool.used = (pool.used + this.length + 7) & ~7; } else { this.parent = zeroBuffer; this.offset = 0; } if (typeof subject !== 'number') { if (type === 'string') { this.length = this.write(subject, 0, encoding);} else if (Buffer.isBuffer(subject)) { if (subject.parent) subject.parent.copy(this.parent, this.offset, subject.offset, this.length + subject.offset); else subject.copy(this.parent, this.offset, 0, this.length); } else if (isArrayIsh(subject)) { for (var i = 0; i < this.length; i++) this.parent[i + this.offset] = subject[i]; } } } SlowBuffer.makeFastBuffer(this.parent, this, this.offset, this.length); } has no method 'from'
答案 0 :(得分:1)
您的Buffer
对象不包含任何from
功能。您没有使用正确的Buffer对象。我想你想使用Node.js缓冲区。确保您真正使用它并且您拥有最新版本。