MCPcopy
hub / github.com/jvilk/BrowserFS / addNewNode

Method addNewNode

src/generic/key_value_filesystem.ts:520–533  ·  view source on GitHub ↗

* Creates a new node under a random ID. Retries 5 times before giving up in * the exceedingly unlikely chance that we try to reuse a random GUID. * @return The GUID that the data was stored under.

(tx: SyncKeyValueRWTransaction, data: Buffer)

Source from the content-addressed store, hash-verified

518 * @return The GUID that the data was stored under.
519 */
520 private addNewNode(tx: SyncKeyValueRWTransaction, data: Buffer): string {
521 const retries = 0;
522 let currId: string;
523 while (retries < 5) {
524 try {
525 currId = GenerateRandomID();
526 tx.put(currId, data, false);
527 return currId;
528 } catch (e) {
529 // Ignore and reroll.
530 }
531 }
532 throw new ApiError(ErrorCode.EIO, 'Unable to commit data to key-value store.');
533 }
534
535 /**
536 * Commits a new file (well, a FILE or a DIRECTORY) to the file system with

Callers 1

commitNewFileMethod · 0.95

Calls 2

GenerateRandomIDFunction · 0.85
putMethod · 0.65

Tested by

no test coverage detected