@zenfs/core 1.2.10 → 1.3.1

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.
Files changed (56) hide show
  1. package/dist/backends/fetch.js +1 -1
  2. package/dist/backends/memory.d.ts +1 -2
  3. package/dist/backends/overlay.js +2 -3
  4. package/dist/backends/port/fs.d.ts +2 -15
  5. package/dist/backends/store/fs.d.ts +17 -28
  6. package/dist/backends/store/fs.js +169 -191
  7. package/dist/backends/store/simple.d.ts +20 -21
  8. package/dist/backends/store/simple.js +24 -24
  9. package/dist/backends/store/store.d.ts +22 -23
  10. package/dist/backends/store/store.js +6 -6
  11. package/dist/config.d.ts +8 -0
  12. package/dist/config.js +20 -20
  13. package/dist/devices.d.ts +2 -3
  14. package/dist/emulation/cache.d.ts +40 -31
  15. package/dist/emulation/cache.js +62 -53
  16. package/dist/emulation/index.d.ts +1 -1
  17. package/dist/emulation/index.js +1 -1
  18. package/dist/emulation/promises.js +18 -17
  19. package/dist/emulation/shared.d.ts +6 -0
  20. package/dist/emulation/shared.js +13 -1
  21. package/dist/emulation/sync.js +14 -13
  22. package/dist/file.d.ts +3 -15
  23. package/dist/file.js +6 -18
  24. package/dist/index.d.ts +7 -0
  25. package/dist/index.js +1 -0
  26. package/dist/inode.d.ts +5 -13
  27. package/dist/inode.js +38 -29
  28. package/dist/mixins/async.d.ts +15 -10
  29. package/dist/mixins/async.js +3 -1
  30. package/dist/utils.d.ts +5 -7
  31. package/dist/utils.js +11 -20
  32. package/package.json +1 -1
  33. package/src/backends/fetch.ts +1 -1
  34. package/src/backends/memory.ts +1 -2
  35. package/src/backends/overlay.ts +2 -2
  36. package/src/backends/store/fs.ts +187 -220
  37. package/src/backends/store/simple.ts +36 -37
  38. package/src/backends/store/store.ts +25 -26
  39. package/src/config.ts +31 -23
  40. package/src/devices.ts +2 -3
  41. package/src/emulation/cache.ts +68 -60
  42. package/src/emulation/index.ts +1 -1
  43. package/src/emulation/promises.ts +20 -19
  44. package/src/emulation/shared.ts +13 -1
  45. package/src/emulation/sync.ts +14 -13
  46. package/src/file.ts +8 -20
  47. package/src/index.ts +10 -0
  48. package/src/inode.ts +27 -31
  49. package/src/mixins/async.ts +27 -24
  50. package/src/utils.ts +11 -23
  51. package/tests/fs/dir.test.ts +21 -31
  52. package/tests/fs/directory.test.ts +6 -4
  53. package/tests/fs/links.test.ts +9 -2
  54. package/tests/fs/permissions.test.ts +2 -2
  55. package/tests/fs/times.test.ts +22 -11
  56. package/tests/setup/cow+fetch.ts +4 -2
package/dist/utils.js CHANGED
@@ -143,21 +143,6 @@ export function decodeDirListing(data) {
143
143
  export function encodeDirListing(data) {
144
144
  return encodeUTF8(JSON.stringify(data, (k, v) => (k == '' ? v : v.toString())));
145
145
  }
146
- /**
147
- * converts Date or number to a integer UNIX timestamp
148
- * Grabbed from NodeJS sources (lib/fs.js)
149
- *
150
- * @internal
151
- */
152
- export function _toUnixTimestamp(time) {
153
- if (typeof time === 'number') {
154
- return Math.floor(time);
155
- }
156
- if (time instanceof Date) {
157
- return Math.floor(time.getTime() / 1000);
158
- }
159
- throw new Error('Cannot parse time');
160
- }
161
146
  /**
162
147
  * Normalizes a mode
163
148
  * @internal
@@ -185,13 +170,12 @@ export function normalizeTime(time) {
185
170
  if (time instanceof Date) {
186
171
  return time;
187
172
  }
188
- if (typeof time == 'number') {
189
- return new Date(time * 1000);
190
- }
191
- if (typeof time == 'string') {
173
+ try {
192
174
  return new Date(time);
193
175
  }
194
- throw new ErrnoError(Errno.EINVAL, 'Invalid time.');
176
+ catch {
177
+ throw new ErrnoError(Errno.EINVAL, 'Invalid time.');
178
+ }
195
179
  }
196
180
  /**
197
181
  * Normalizes a path
@@ -229,3 +213,10 @@ export function normalizeOptions(options, encoding = 'utf8', flag, mode = 0) {
229
213
  mode: normalizeMode('mode' in options ? options?.mode : null, mode),
230
214
  };
231
215
  }
216
+ /**
217
+ * Generate a random ino
218
+ * @internal
219
+ */
220
+ export function randomBigInt() {
221
+ return crypto.getRandomValues(new BigUint64Array(1))[0];
222
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zenfs/core",
3
- "version": "1.2.10",
3
+ "version": "1.3.1",
4
4
  "description": "A filesystem, anywhere",
5
5
  "funding": {
6
6
  "type": "individual",
@@ -106,7 +106,7 @@ export class FetchFS extends IndexFS {
106
106
  baseUrl += '/';
107
107
  }
108
108
 
109
- super(typeof index != 'string' ? index : fetchFile<IndexData>(baseUrl + index, 'json', requestInit));
109
+ super(typeof index != 'string' ? index : fetchFile<IndexData>(index, 'json', requestInit));
110
110
 
111
111
  this.baseUrl = baseUrl;
112
112
  this.requestInit = requestInit;
@@ -1,4 +1,3 @@
1
- import type { Ino } from '../inode.js';
2
1
  import type { Backend } from './backend.js';
3
2
  import { StoreFS } from './store/fs.js';
4
3
  import { SimpleTransaction, type SimpleSyncStore } from './store/simple.js';
@@ -6,7 +5,7 @@ import { SimpleTransaction, type SimpleSyncStore } from './store/simple.js';
6
5
  /**
7
6
  * A simple in-memory store
8
7
  */
9
- export class InMemoryStore extends Map<Ino, Uint8Array> implements SimpleSyncStore {
8
+ export class InMemoryStore extends Map<bigint, Uint8Array> implements SimpleSyncStore {
10
9
  public constructor(public name: string = 'tmp') {
11
10
  super();
12
11
  }
@@ -159,7 +159,7 @@ export class UnmutexedOverlayFS extends FileSystem {
159
159
  if (this._deletedFiles.has(path)) {
160
160
  throw ErrnoError.With('ENOENT', path, 'stat');
161
161
  }
162
- const oldStat = new Stats(await this.readable.stat(path));
162
+ const oldStat = await this.readable.stat(path);
163
163
  // Make the oldStat's mode writable.
164
164
  oldStat.mode |= 0o222;
165
165
  return oldStat;
@@ -174,7 +174,7 @@ export class UnmutexedOverlayFS extends FileSystem {
174
174
  if (this._deletedFiles.has(path)) {
175
175
  throw ErrnoError.With('ENOENT', path, 'stat');
176
176
  }
177
- const oldStat = new Stats(this.readable.statSync(path));
177
+ const oldStat = this.readable.statSync(path);
178
178
  // Make the oldStat's mode writable.
179
179
  oldStat.mode |= 0o222;
180
180
  return oldStat;