MCPcopy
hub / github.com/pyodide/pyodide / readWriteHelper

Function readWriteHelper

src/js/streams.ts:168–197  ·  view source on GitHub ↗
(stream: Stream, cb: () => number, method: string)

Source from the content-addressed store, hash-verified

166}
167
168function readWriteHelper(stream: Stream, cb: () => number, method: string) {
169 let nbytes;
170 try {
171 nbytes = handleEAGAIN(cb);
172 } catch (e: any) {
173 if (e && e.code && Module.ERRNO_CODES[e.code]) {
174 throw new FS.ErrnoError(Module.ERRNO_CODES[e.code]);
175 }
176 if (isErrnoError(e)) {
177 // the handler set an errno, propagate it
178 throw e;
179 }
180 console.error(`Error thrown in ${method}:`);
181 console.error(e);
182 throw new FS.ErrnoError(cDefs.EIO);
183 }
184 if (nbytes === undefined) {
185 // Prevent an infinite loop caused by incorrect code that doesn't return a
186 // value
187 // Maybe we should set nbytes = buffer.length here instead?
188 console.warn(
189 `${method} returned undefined; a correct implementation must return a number`,
190 );
191 throw new FS.ErrnoError(cDefs.EIO);
192 }
193 if (nbytes !== 0) {
194 stream.node.timestamp = Date.now();
195 }
196 return nbytes;
197}
198
199const prepareBuffer = (
200 buffer: Uint8Array,

Callers 1

streams.tsFile · 0.85

Calls 2

handleEAGAINFunction · 0.85
isErrnoErrorFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…