zen-fs-config 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +34 -40
- package/dist/index.mjs +34 -40
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -316,59 +316,53 @@ function hasBackend(type) {
|
|
|
316
316
|
function listBackends() {
|
|
317
317
|
return Array.from(registry.keys());
|
|
318
318
|
}
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
319
|
+
var inMemoryCounter = 0;
|
|
320
|
+
registerBackend("InMemory", async (options) => {
|
|
321
|
+
const zenfs = await import("@zenfs/core");
|
|
322
|
+
const { InMemory } = zenfs;
|
|
323
|
+
const maxSize = options.maxSize ?? 100 * 1024 * 1024;
|
|
324
|
+
const label = options.label ?? `zen-fs-config-${++inMemoryCounter}`;
|
|
325
|
+
await zenfs.configureSingle({ backend: InMemory, maxSize, label });
|
|
326
|
+
const pfs = zenfs.fs.promises;
|
|
327
|
+
const backend = {
|
|
328
|
+
async readFile(path, ...args) {
|
|
329
|
+
if (args.length > 0) {
|
|
330
|
+
return pfs.readFile(path, ...args);
|
|
331
|
+
}
|
|
332
|
+
return pfs.readFile(path);
|
|
324
333
|
},
|
|
325
|
-
writeFile(path, data,
|
|
326
|
-
|
|
327
|
-
return Promise.resolve();
|
|
334
|
+
async writeFile(path, data, options2) {
|
|
335
|
+
return pfs.writeFile(path, data, options2);
|
|
328
336
|
},
|
|
329
|
-
readdir(path) {
|
|
330
|
-
const entries =
|
|
331
|
-
return
|
|
337
|
+
async readdir(path) {
|
|
338
|
+
const entries = await pfs.readdir(path);
|
|
339
|
+
return entries.map((e) => typeof e === "string" ? e : e.name);
|
|
332
340
|
},
|
|
333
|
-
stat(path, ...args) {
|
|
334
|
-
return
|
|
341
|
+
async stat(path, ...args) {
|
|
342
|
+
return pfs.stat(path, ...args);
|
|
335
343
|
},
|
|
336
|
-
exists(path) {
|
|
344
|
+
async exists(path) {
|
|
337
345
|
try {
|
|
338
|
-
|
|
339
|
-
return
|
|
346
|
+
await pfs.stat(path);
|
|
347
|
+
return true;
|
|
340
348
|
} catch {
|
|
341
|
-
return
|
|
349
|
+
return false;
|
|
342
350
|
}
|
|
343
351
|
},
|
|
344
|
-
mkdir(path,
|
|
345
|
-
|
|
346
|
-
return Promise.resolve();
|
|
352
|
+
async mkdir(path, options2) {
|
|
353
|
+
return pfs.mkdir(path, options2);
|
|
347
354
|
},
|
|
348
|
-
unlink(path) {
|
|
349
|
-
|
|
350
|
-
return Promise.resolve();
|
|
355
|
+
async unlink(path) {
|
|
356
|
+
return pfs.unlink(path);
|
|
351
357
|
},
|
|
352
|
-
rmdir(path) {
|
|
353
|
-
|
|
354
|
-
backend.rmdir(path);
|
|
355
|
-
}
|
|
356
|
-
return Promise.resolve();
|
|
358
|
+
async rmdir(path) {
|
|
359
|
+
return pfs.rmdir(path);
|
|
357
360
|
},
|
|
358
|
-
rename(oldPath, newPath) {
|
|
359
|
-
|
|
360
|
-
backend.rename(oldPath, newPath);
|
|
361
|
-
}
|
|
362
|
-
return Promise.resolve();
|
|
361
|
+
async rename(oldPath, newPath) {
|
|
362
|
+
return pfs.rename(oldPath, newPath);
|
|
363
363
|
}
|
|
364
364
|
};
|
|
365
|
-
|
|
366
|
-
registerBackend("InMemory", async (options) => {
|
|
367
|
-
const { InMemory } = await import("@zenfs/core");
|
|
368
|
-
const maxSize = options.maxSize ?? 100 * 1024 * 1024;
|
|
369
|
-
const label = options.label ?? "zen-fs-config";
|
|
370
|
-
const fs = InMemory.create({ maxSize, label });
|
|
371
|
-
return syncToAsync(fs);
|
|
365
|
+
return backend;
|
|
372
366
|
});
|
|
373
367
|
|
|
374
368
|
// src/version.ts
|
package/dist/index.mjs
CHANGED
|
@@ -269,59 +269,53 @@ function hasBackend(type) {
|
|
|
269
269
|
function listBackends() {
|
|
270
270
|
return Array.from(registry.keys());
|
|
271
271
|
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
272
|
+
var inMemoryCounter = 0;
|
|
273
|
+
registerBackend("InMemory", async (options) => {
|
|
274
|
+
const zenfs = await import("@zenfs/core");
|
|
275
|
+
const { InMemory } = zenfs;
|
|
276
|
+
const maxSize = options.maxSize ?? 100 * 1024 * 1024;
|
|
277
|
+
const label = options.label ?? `zen-fs-config-${++inMemoryCounter}`;
|
|
278
|
+
await zenfs.configureSingle({ backend: InMemory, maxSize, label });
|
|
279
|
+
const pfs = zenfs.fs.promises;
|
|
280
|
+
const backend = {
|
|
281
|
+
async readFile(path, ...args) {
|
|
282
|
+
if (args.length > 0) {
|
|
283
|
+
return pfs.readFile(path, ...args);
|
|
284
|
+
}
|
|
285
|
+
return pfs.readFile(path);
|
|
277
286
|
},
|
|
278
|
-
writeFile(path, data,
|
|
279
|
-
|
|
280
|
-
return Promise.resolve();
|
|
287
|
+
async writeFile(path, data, options2) {
|
|
288
|
+
return pfs.writeFile(path, data, options2);
|
|
281
289
|
},
|
|
282
|
-
readdir(path) {
|
|
283
|
-
const entries =
|
|
284
|
-
return
|
|
290
|
+
async readdir(path) {
|
|
291
|
+
const entries = await pfs.readdir(path);
|
|
292
|
+
return entries.map((e) => typeof e === "string" ? e : e.name);
|
|
285
293
|
},
|
|
286
|
-
stat(path, ...args) {
|
|
287
|
-
return
|
|
294
|
+
async stat(path, ...args) {
|
|
295
|
+
return pfs.stat(path, ...args);
|
|
288
296
|
},
|
|
289
|
-
exists(path) {
|
|
297
|
+
async exists(path) {
|
|
290
298
|
try {
|
|
291
|
-
|
|
292
|
-
return
|
|
299
|
+
await pfs.stat(path);
|
|
300
|
+
return true;
|
|
293
301
|
} catch {
|
|
294
|
-
return
|
|
302
|
+
return false;
|
|
295
303
|
}
|
|
296
304
|
},
|
|
297
|
-
mkdir(path,
|
|
298
|
-
|
|
299
|
-
return Promise.resolve();
|
|
305
|
+
async mkdir(path, options2) {
|
|
306
|
+
return pfs.mkdir(path, options2);
|
|
300
307
|
},
|
|
301
|
-
unlink(path) {
|
|
302
|
-
|
|
303
|
-
return Promise.resolve();
|
|
308
|
+
async unlink(path) {
|
|
309
|
+
return pfs.unlink(path);
|
|
304
310
|
},
|
|
305
|
-
rmdir(path) {
|
|
306
|
-
|
|
307
|
-
backend.rmdir(path);
|
|
308
|
-
}
|
|
309
|
-
return Promise.resolve();
|
|
311
|
+
async rmdir(path) {
|
|
312
|
+
return pfs.rmdir(path);
|
|
310
313
|
},
|
|
311
|
-
rename(oldPath, newPath) {
|
|
312
|
-
|
|
313
|
-
backend.rename(oldPath, newPath);
|
|
314
|
-
}
|
|
315
|
-
return Promise.resolve();
|
|
314
|
+
async rename(oldPath, newPath) {
|
|
315
|
+
return pfs.rename(oldPath, newPath);
|
|
316
316
|
}
|
|
317
317
|
};
|
|
318
|
-
|
|
319
|
-
registerBackend("InMemory", async (options) => {
|
|
320
|
-
const { InMemory } = await import("@zenfs/core");
|
|
321
|
-
const maxSize = options.maxSize ?? 100 * 1024 * 1024;
|
|
322
|
-
const label = options.label ?? "zen-fs-config";
|
|
323
|
-
const fs = InMemory.create({ maxSize, label });
|
|
324
|
-
return syncToAsync(fs);
|
|
318
|
+
return backend;
|
|
325
319
|
});
|
|
326
320
|
|
|
327
321
|
// src/version.ts
|