@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.
- package/dist/backends/fetch.js +1 -1
- package/dist/backends/memory.d.ts +1 -2
- package/dist/backends/overlay.js +2 -3
- package/dist/backends/port/fs.d.ts +2 -15
- package/dist/backends/store/fs.d.ts +17 -28
- package/dist/backends/store/fs.js +169 -191
- package/dist/backends/store/simple.d.ts +20 -21
- package/dist/backends/store/simple.js +24 -24
- package/dist/backends/store/store.d.ts +22 -23
- package/dist/backends/store/store.js +6 -6
- package/dist/config.d.ts +8 -0
- package/dist/config.js +20 -20
- package/dist/devices.d.ts +2 -3
- package/dist/emulation/cache.d.ts +40 -31
- package/dist/emulation/cache.js +62 -53
- package/dist/emulation/index.d.ts +1 -1
- package/dist/emulation/index.js +1 -1
- package/dist/emulation/promises.js +18 -17
- package/dist/emulation/shared.d.ts +6 -0
- package/dist/emulation/shared.js +13 -1
- package/dist/emulation/sync.js +14 -13
- package/dist/file.d.ts +3 -15
- package/dist/file.js +6 -18
- package/dist/index.d.ts +7 -0
- package/dist/index.js +1 -0
- package/dist/inode.d.ts +5 -13
- package/dist/inode.js +38 -29
- package/dist/mixins/async.d.ts +15 -10
- package/dist/mixins/async.js +3 -1
- package/dist/utils.d.ts +5 -7
- package/dist/utils.js +11 -20
- package/package.json +1 -1
- package/src/backends/fetch.ts +1 -1
- package/src/backends/memory.ts +1 -2
- package/src/backends/overlay.ts +2 -2
- package/src/backends/store/fs.ts +187 -220
- package/src/backends/store/simple.ts +36 -37
- package/src/backends/store/store.ts +25 -26
- package/src/config.ts +31 -23
- package/src/devices.ts +2 -3
- package/src/emulation/cache.ts +68 -60
- package/src/emulation/index.ts +1 -1
- package/src/emulation/promises.ts +20 -19
- package/src/emulation/shared.ts +13 -1
- package/src/emulation/sync.ts +14 -13
- package/src/file.ts +8 -20
- package/src/index.ts +10 -0
- package/src/inode.ts +27 -31
- package/src/mixins/async.ts +27 -24
- package/src/utils.ts +11 -23
- package/tests/fs/dir.test.ts +21 -31
- package/tests/fs/directory.test.ts +6 -4
- package/tests/fs/links.test.ts +9 -2
- package/tests/fs/permissions.test.ts +2 -2
- package/tests/fs/times.test.ts +22 -11
- 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
|
-
|
|
189
|
-
return new Date(time * 1000);
|
|
190
|
-
}
|
|
191
|
-
if (typeof time == 'string') {
|
|
173
|
+
try {
|
|
192
174
|
return new Date(time);
|
|
193
175
|
}
|
|
194
|
-
|
|
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
package/src/backends/fetch.ts
CHANGED
|
@@ -106,7 +106,7 @@ export class FetchFS extends IndexFS {
|
|
|
106
106
|
baseUrl += '/';
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
super(typeof index != 'string' ? index : fetchFile<IndexData>(
|
|
109
|
+
super(typeof index != 'string' ? index : fetchFile<IndexData>(index, 'json', requestInit));
|
|
110
110
|
|
|
111
111
|
this.baseUrl = baseUrl;
|
|
112
112
|
this.requestInit = requestInit;
|
package/src/backends/memory.ts
CHANGED
|
@@ -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<
|
|
8
|
+
export class InMemoryStore extends Map<bigint, Uint8Array> implements SimpleSyncStore {
|
|
10
9
|
public constructor(public name: string = 'tmp') {
|
|
11
10
|
super();
|
|
12
11
|
}
|
package/src/backends/overlay.ts
CHANGED
|
@@ -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 =
|
|
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 =
|
|
177
|
+
const oldStat = this.readable.statSync(path);
|
|
178
178
|
// Make the oldStat's mode writable.
|
|
179
179
|
oldStat.mode |= 0o222;
|
|
180
180
|
return oldStat;
|