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

Function readOperation

out/cli.cjs:61208–61275  ·  view source on GitHub ↗
(fr2, blob, type2, encodingName)

Source from the content-addressed store, hash-verified

61206 var { types } = require("util");
61207 var { StringDecoder } = require("string_decoder");
61208 var { btoa: btoa2 } = require("buffer");
61209 var staticPropertyDescriptors = {
61210 enumerable: true,
61211 writable: false,
61212 configurable: false
61213 };
61214 function readOperation(fr2, blob, type2, encodingName) {
61215 if (fr2[kState] === "loading") {
61216 throw new DOMException3("Invalid state", "InvalidStateError");
61217 }
61218 fr2[kState] = "loading";
61219 fr2[kResult] = null;
61220 fr2[kError] = null;
61221 const stream4 = blob.stream();
61222 const reader = stream4.getReader();
61223 const bytes = [];
61224 let chunkPromise = reader.read();
61225 let isFirstChunk = true;
61226 (async () => {
61227 while (!fr2[kAborted]) {
61228 try {
61229 const { done, value } = await chunkPromise;
61230 if (isFirstChunk && !fr2[kAborted]) {
61231 queueMicrotask(() => {
61232 fireAProgressEvent("loadstart", fr2);
61233 });
61234 }
61235 isFirstChunk = false;
61236 if (!done && types.isUint8Array(value)) {
61237 bytes.push(value);
61238 if ((fr2[kLastProgressEventFired] === void 0 || Date.now() - fr2[kLastProgressEventFired] >= 50) && !fr2[kAborted]) {
61239 fr2[kLastProgressEventFired] = Date.now();
61240 queueMicrotask(() => {
61241 fireAProgressEvent("progress", fr2);
61242 });
61243 }
61244 chunkPromise = reader.read();
61245 } else if (done) {
61246 queueMicrotask(() => {
61247 fr2[kState] = "done";
61248 try {
61249 const result = packageData(bytes, type2, blob.type, encodingName);
61250 if (fr2[kAborted]) {
61251 return;
61252 }
61253 fr2[kResult] = result;
61254 fireAProgressEvent("load", fr2);
61255 } catch (error) {
61256 fr2[kError] = error;
61257 fireAProgressEvent("error", fr2);
61258 }
61259 if (fr2[kState] !== "loading") {
61260 fireAProgressEvent("loadend", fr2);
61261 }
61262 });
61263 break;
61264 }
61265 } catch (error) {

Callers 4

readAsArrayBufferMethod · 0.85
readAsBinaryStringMethod · 0.85
readAsTextMethod · 0.85
readAsDataURLMethod · 0.85

Calls 6

fireAProgressEventFunction · 0.85
packageDataFunction · 0.85
streamMethod · 0.45
getReaderMethod · 0.45
readMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…