@zenfs/core
Advanced tools
Comparing version 0.5.3 to 0.5.4
@@ -410,22 +410,14 @@ import { dirname, basename, join, resolve } from '../emulation/path.js'; | ||
*/ | ||
async addNewNode(tx, data) { | ||
let retries = 0; | ||
const reroll = async () => { | ||
if (++retries === 5) { | ||
// Max retries hit. Return with an error. | ||
throw new ApiError(ErrorCode.EIO, 'Unable to commit data to key-value store.'); | ||
} | ||
else { | ||
// Try again. | ||
const ino = randomIno(); | ||
const committed = await tx.put(ino, data, false); | ||
if (!committed) { | ||
return reroll(); | ||
} | ||
else { | ||
return ino; | ||
} | ||
} | ||
}; | ||
return reroll(); | ||
async addNewNode(tx, data, _maxAttempts = 5) { | ||
if (_maxAttempts <= 0) { | ||
// Max retries hit. Return with an error. | ||
throw new ApiError(ErrorCode.EIO, 'Unable to commit data to key-value store.'); | ||
} | ||
// Make an attempt | ||
const ino = randomIno(); | ||
const isCommited = await tx.put(ino, data, false); | ||
if (!isCommited) { | ||
return await this.addNewNode(tx, data, --_maxAttempts); | ||
} | ||
return ino; | ||
} | ||
@@ -432,0 +424,0 @@ /** |
@@ -205,3 +205,3 @@ import { Cred } from '../cred.js'; | ||
*/ | ||
protected addNewNode(tx: SyncTransaction, data: Uint8Array): Ino; | ||
protected addNewNode(tx: SyncTransaction, data: Uint8Array, _maxAttempts?: number): Ino; | ||
/** | ||
@@ -208,0 +208,0 @@ * Commits a new file (well, a FILE or a DIRECTORY) to the file system with the given mode. |
@@ -374,14 +374,9 @@ import { dirname, basename, join, resolve, sep } from '../emulation/path.js'; | ||
*/ | ||
addNewNode(tx, data) { | ||
const retries = 0; | ||
let ino; | ||
while (retries < 5) { | ||
try { | ||
ino = randomIno(); | ||
tx.put(ino, data, false); | ||
return ino; | ||
addNewNode(tx, data, _maxAttempts = 5) { | ||
for (let i = 0; i < _maxAttempts; i++) { | ||
const ino = randomIno(); | ||
if (!tx.put(ino, data, false)) { | ||
continue; | ||
} | ||
catch (e) { | ||
// Ignore and reroll. | ||
} | ||
return ino; | ||
} | ||
@@ -388,0 +383,0 @@ throw new ApiError(ErrorCode.EIO, 'Unable to commit data to key-value store.'); |
{ | ||
"name": "@zenfs/core", | ||
"version": "0.5.3", | ||
"version": "0.5.4", | ||
"description": "A filesystem in your browser", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -20,3 +20,3 @@ # ZenFS | ||
ZenFS supports a number of other backends. Many are provided as seperate packages under `@zenfs`. More backends can be defined by separate libraries by extending the `FileSystem` class and/or providing a `Backend` object. | ||
ZenFS supports a number of other backends. Many are provided as separate packages under `@zenfs`. More backends can be defined by separate libraries by extending the `FileSystem` class and/or providing a `Backend` object. | ||
@@ -114,3 +114,3 @@ For more information, see the [docs](https://zen-fs.github.io/core). | ||
> [!IMPORTANT] | ||
> ZenFS does _not_ provide a seperate public import for importing promises like `fs/promises`. If you are using ESM, you can import promises functions like `fs/promises` from the `dist/emulation/promises.ts` file, though this may change at any time and is **not recommended**. | ||
> ZenFS does _not_ provide a separate public import for importing promises like `fs/promises`. If you are using ESM, you can import promises functions like `fs/promises` from the `dist/emulation/promises.ts` file, though this may change at any time and is **not recommended**. | ||
@@ -117,0 +117,0 @@ #### Using asynchronous backends synchronously |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1472364
11335