MCPcopy
hub / github.com/di-sukharev/opencommit / consumeBody

Function consumeBody

out/cli.cjs:6217–6282  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

6215 }
6216 };
6217 function consumeBody() {
6218 var _this4 = this;
6219 if (this[INTERNALS].disturbed) {
6220 return Body.Promise.reject(new TypeError(`body used already for: ${this.url}`));
6221 }
6222 this[INTERNALS].disturbed = true;
6223 if (this[INTERNALS].error) {
6224 return Body.Promise.reject(this[INTERNALS].error);
6225 }
6226 let body = this.body;
6227 if (body === null) {
6228 return Body.Promise.resolve(Buffer.alloc(0));
6229 }
6230 if (isBlob4(body)) {
6231 body = body.stream();
6232 }
6233 if (Buffer.isBuffer(body)) {
6234 return Body.Promise.resolve(body);
6235 }
6236 if (!(body instanceof Stream3)) {
6237 return Body.Promise.resolve(Buffer.alloc(0));
6238 }
6239 let accum = [];
6240 let accumBytes = 0;
6241 let abort = false;
6242 return new Body.Promise(function(resolve, reject) {
6243 let resTimeout;
6244 if (_this4.timeout) {
6245 resTimeout = setTimeout(function() {
6246 abort = true;
6247 reject(new FetchError(`Response timeout while trying to fetch ${_this4.url} (over ${_this4.timeout}ms)`, "body-timeout"));
6248 }, _this4.timeout);
6249 }
6250 body.on("error", function(err) {
6251 if (err.name === "AbortError") {
6252 abort = true;
6253 reject(err);
6254 } else {
6255 reject(new FetchError(`Invalid response body while trying to fetch ${_this4.url}: ${err.message}`, "system", err));
6256 }
6257 });
6258 body.on("data", function(chunk) {
6259 if (abort || chunk === null) {
6260 return;
6261 }
6262 if (_this4.size && accumBytes + chunk.length > _this4.size) {
6263 abort = true;
6264 reject(new FetchError(`content size at ${_this4.url} over limit: ${_this4.size}`, "max-size"));
6265 return;
6266 }
6267 accumBytes += chunk.length;
6268 accum.push(chunk);
6269 });
6270 body.on("end", function() {
6271 if (abort) {
6272 return;
6273 }
6274 clearTimeout(resTimeout);

Callers 1

formDataFunction · 0.85

Calls 8

isBlob4Function · 0.85
setTimeoutFunction · 0.85
rejectFunction · 0.85
clearTimeoutFunction · 0.85
concatMethod · 0.80
streamMethod · 0.45
onMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…