Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async json() {
this._ensureUnused();
if (this._body == null)
return Promise.resolve(this.validateIntegrity(emptyBuffer, false))
.then(() => this._body);
else if (isStream(this._body))
return get_stream_1.buffer(this._body)
.then(already_1.tap(buffer => this.validateIntegrity(buffer, false)))
.then(buffer => JSON.parse(buffer.toString()));
else if (isBuffer(this._body))
return Promise.resolve(this._body)
.then(already_1.tap(buffer => this.validateIntegrity(buffer, false)))
.then(buffer => JSON.parse(buffer.toString()));
else
throwUnknownData();
}
async text(allowIncomplete = false) {
async text(allowIncomplete = false) {
this._ensureUnused();
if (this._body == null)
return Promise.resolve(this.validateIntegrity(emptyBuffer, allowIncomplete))
.then(() => this._body);
else if (isStream(this._body))
return get_stream_1.buffer(this._body)
.then(already_1.tap(buffer => this.validateIntegrity(buffer, allowIncomplete)))
.then(buffer => buffer.toString());
else if (isBuffer(this._body))
return Promise.resolve(this._body)
.then(already_1.tap(buffer => this.validateIntegrity(buffer, allowIncomplete)))
.then(buffer => buffer.toString());
else
return throwUnknownData();
}
async readable() {