@zenfs/core 0.0.11 → 0.0.12
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/AsyncMirror.js +5 -5
- package/dist/backends/Locked.d.ts +7 -8
- package/dist/backends/Locked.js +12 -12
- package/dist/backends/OverlayFS.js +12 -11
- package/dist/browser.min.js +6 -6
- package/dist/browser.min.js.map +3 -3
- package/dist/emulation/promises.js +19 -4
- package/dist/emulation/sync.js +19 -4
- package/dist/filesystem.d.ts +12 -20
- package/dist/filesystem.js +9 -15
- package/dist/utils.d.ts +6 -4
- package/dist/utils.js +4 -2
- package/package.json +1 -1
|
@@ -12,7 +12,7 @@ import * as constants from './constants.js';
|
|
|
12
12
|
export { constants };
|
|
13
13
|
import { FileFlag } from '../file.js';
|
|
14
14
|
import { normalizePath, normalizeMode, getFdForFile, normalizeOptions, fd2file, fdMap, normalizeTime, cred, nop, resolveFS, fixError, mounts } from './shared.js';
|
|
15
|
-
import { encode } from '../utils.js';
|
|
15
|
+
import { decode, encode } from '../utils.js';
|
|
16
16
|
/**
|
|
17
17
|
* Utility for FS ops. It handles
|
|
18
18
|
* - path normalization (for the first parameter to the FS op)
|
|
@@ -148,7 +148,14 @@ export function readFile(filename, arg2 = {}) {
|
|
|
148
148
|
if (!flag.isReadable()) {
|
|
149
149
|
throw new ApiError(ErrorCode.EINVAL, 'Flag passed to readFile must allow for reading.');
|
|
150
150
|
}
|
|
151
|
-
|
|
151
|
+
const data = yield doOp('readFile', true, filename, flag, cred);
|
|
152
|
+
switch (options.encoding) {
|
|
153
|
+
case 'utf8':
|
|
154
|
+
case 'utf-8':
|
|
155
|
+
return decode(data);
|
|
156
|
+
default:
|
|
157
|
+
return data;
|
|
158
|
+
}
|
|
152
159
|
});
|
|
153
160
|
}
|
|
154
161
|
export function writeFile(filename, data, arg3) {
|
|
@@ -158,7 +165,11 @@ export function writeFile(filename, data, arg3) {
|
|
|
158
165
|
if (!flag.isWriteable()) {
|
|
159
166
|
throw new ApiError(ErrorCode.EINVAL, 'Flag passed to writeFile must allow for writing.');
|
|
160
167
|
}
|
|
161
|
-
|
|
168
|
+
if (typeof data != 'string' && !options.encoding) {
|
|
169
|
+
throw new ApiError(ErrorCode.EINVAL, 'Encoding not specified');
|
|
170
|
+
}
|
|
171
|
+
const encodedData = typeof data == 'string' ? encode(data) : data;
|
|
172
|
+
return doOp('writeFile', true, filename, encodedData, flag, options.mode, cred);
|
|
162
173
|
});
|
|
163
174
|
}
|
|
164
175
|
export function appendFile(filename, data, arg3) {
|
|
@@ -168,7 +179,11 @@ export function appendFile(filename, data, arg3) {
|
|
|
168
179
|
if (!flag.isAppendable()) {
|
|
169
180
|
throw new ApiError(ErrorCode.EINVAL, 'Flag passed to appendFile must allow for appending.');
|
|
170
181
|
}
|
|
171
|
-
|
|
182
|
+
if (typeof data != 'string' && !options.encoding) {
|
|
183
|
+
throw new ApiError(ErrorCode.EINVAL, 'Encoding not specified');
|
|
184
|
+
}
|
|
185
|
+
const encodedData = typeof data == 'string' ? encode(data) : data;
|
|
186
|
+
return doOp('appendFile', true, filename, encodedData, flag, options.mode, cred);
|
|
172
187
|
});
|
|
173
188
|
}
|
|
174
189
|
// FILE DESCRIPTOR METHODS
|
package/dist/emulation/sync.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ApiError, ErrorCode } from '../ApiError.js';
|
|
2
2
|
import { FileFlag } from '../file.js';
|
|
3
3
|
import { normalizePath, cred, getFdForFile, normalizeMode, normalizeOptions, fdMap, fd2file, normalizeTime, resolveFS, fixError, mounts } from './shared.js';
|
|
4
|
-
import { encode } from '../utils.js';
|
|
4
|
+
import { decode, encode } from '../utils.js';
|
|
5
5
|
function doOp(...[name, resolveSymlinks, path, ...args]) {
|
|
6
6
|
path = normalizePath(path);
|
|
7
7
|
const { fs, path: resolvedPath } = resolveFS(resolveSymlinks && existsSync(path) ? realpathSync(path) : path);
|
|
@@ -107,7 +107,14 @@ export function readFileSync(filename, arg2 = {}) {
|
|
|
107
107
|
if (!flag.isReadable()) {
|
|
108
108
|
throw new ApiError(ErrorCode.EINVAL, 'Flag passed to readFile must allow for reading.');
|
|
109
109
|
}
|
|
110
|
-
|
|
110
|
+
const data = doOp('readFileSync', true, filename, flag, cred);
|
|
111
|
+
switch (options.encoding) {
|
|
112
|
+
case 'utf8':
|
|
113
|
+
case 'utf-8':
|
|
114
|
+
return decode(data);
|
|
115
|
+
default:
|
|
116
|
+
return data;
|
|
117
|
+
}
|
|
111
118
|
}
|
|
112
119
|
export function writeFileSync(filename, data, arg3) {
|
|
113
120
|
const options = normalizeOptions(arg3, 'utf8', 'w', 0o644);
|
|
@@ -115,7 +122,11 @@ export function writeFileSync(filename, data, arg3) {
|
|
|
115
122
|
if (!flag.isWriteable()) {
|
|
116
123
|
throw new ApiError(ErrorCode.EINVAL, 'Flag passed to writeFile must allow for writing.');
|
|
117
124
|
}
|
|
118
|
-
|
|
125
|
+
if (typeof data != 'string' && !options.encoding) {
|
|
126
|
+
throw new ApiError(ErrorCode.EINVAL, 'Encoding not specified');
|
|
127
|
+
}
|
|
128
|
+
const encodedData = typeof data == 'string' ? encode(data) : data;
|
|
129
|
+
return doOp('writeFileSync', true, filename, encodedData, flag, options.mode, cred);
|
|
119
130
|
}
|
|
120
131
|
export function appendFileSync(filename, data, arg3) {
|
|
121
132
|
const options = normalizeOptions(arg3, 'utf8', 'a', 0o644);
|
|
@@ -123,7 +134,11 @@ export function appendFileSync(filename, data, arg3) {
|
|
|
123
134
|
if (!flag.isAppendable()) {
|
|
124
135
|
throw new ApiError(ErrorCode.EINVAL, 'Flag passed to appendFile must allow for appending.');
|
|
125
136
|
}
|
|
126
|
-
|
|
137
|
+
if (typeof data != 'string' && !options.encoding) {
|
|
138
|
+
throw new ApiError(ErrorCode.EINVAL, 'Encoding not specified');
|
|
139
|
+
}
|
|
140
|
+
const encodedData = typeof data == 'string' ? encode(data) : data;
|
|
141
|
+
return doOp('appendFileSync', true, filename, encodedData, flag, options.mode, cred);
|
|
127
142
|
}
|
|
128
143
|
/**
|
|
129
144
|
* Synchronous `fstat`.
|
package/dist/filesystem.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
2
1
|
import { ApiError } from './ApiError.js';
|
|
3
2
|
import { Stats } from './stats.js';
|
|
4
3
|
import { File, FileFlag } from './file.js';
|
|
@@ -179,43 +178,36 @@ export declare abstract class FileSystem {
|
|
|
179
178
|
abstract truncateSync(p: string, len: number, cred: Cred): void;
|
|
180
179
|
/**
|
|
181
180
|
* Asynchronously reads the entire contents of a file.
|
|
182
|
-
* @param encoding If non-null, the file's contents should be decoded
|
|
183
|
-
* into a string using that encoding. Otherwise, if encoding is null, fetch
|
|
184
|
-
* the file's contents as a Uint8Array.
|
|
185
|
-
* If no encoding is specified, then the raw buffer is returned.
|
|
186
181
|
*/
|
|
187
|
-
abstract readFile(fname: string,
|
|
182
|
+
abstract readFile(fname: string, flag: FileFlag, cred: Cred): Promise<Uint8Array>;
|
|
188
183
|
/**
|
|
189
184
|
* Synchronously reads the entire contents of a file.
|
|
190
|
-
* @param encoding If non-null, the file's contents should be decoded
|
|
191
|
-
* into a string using that encoding. Otherwise, if encoding is null, fetch
|
|
192
|
-
* the file's contents as a Uint8Array.
|
|
193
185
|
*/
|
|
194
|
-
abstract readFileSync(fname: string,
|
|
186
|
+
abstract readFileSync(fname: string, flag: FileFlag, cred: Cred): Uint8Array;
|
|
195
187
|
/**
|
|
196
188
|
* Asynchronously writes data to a file, replacing the file
|
|
197
189
|
* if it already exists.
|
|
198
190
|
*
|
|
199
191
|
* The encoding option is ignored if data is a buffer.
|
|
200
192
|
*/
|
|
201
|
-
abstract writeFile(fname: string, data:
|
|
193
|
+
abstract writeFile(fname: string, data: Uint8Array, flag: FileFlag, mode: number, cred: Cred): Promise<void>;
|
|
202
194
|
/**
|
|
203
195
|
* Synchronously writes data to a file, replacing the file
|
|
204
196
|
* if it already exists.
|
|
205
197
|
*
|
|
206
198
|
* The encoding option is ignored if data is a buffer.
|
|
207
199
|
*/
|
|
208
|
-
abstract writeFileSync(fname: string, data:
|
|
200
|
+
abstract writeFileSync(fname: string, data: Uint8Array, flag: FileFlag, mode: number, cred: Cred): void;
|
|
209
201
|
/**
|
|
210
202
|
* Asynchronously append data to a file, creating the file if
|
|
211
203
|
* it not yet exists.
|
|
212
204
|
*/
|
|
213
|
-
abstract appendFile(fname: string, data:
|
|
205
|
+
abstract appendFile(fname: string, data: Uint8Array, flag: FileFlag, mode: number, cred: Cred): Promise<void>;
|
|
214
206
|
/**
|
|
215
207
|
* Synchronously append data to a file, creating the file if
|
|
216
208
|
* it not yet exists.
|
|
217
209
|
*/
|
|
218
|
-
abstract appendFileSync(fname: string, data:
|
|
210
|
+
abstract appendFileSync(fname: string, data: Uint8Array, flag: FileFlag, mode: number, cred: Cred): void;
|
|
219
211
|
/**
|
|
220
212
|
* Asynchronous `chmod`.
|
|
221
213
|
*/
|
|
@@ -326,12 +318,12 @@ export declare class BaseFileSystem extends FileSystem {
|
|
|
326
318
|
realpathSync(p: string, cred: Cred): string;
|
|
327
319
|
truncate(p: string, len: number, cred: Cred): Promise<void>;
|
|
328
320
|
truncateSync(p: string, len: number, cred: Cred): void;
|
|
329
|
-
readFile(fname: string,
|
|
330
|
-
readFileSync(fname: string,
|
|
331
|
-
writeFile(fname: string, data:
|
|
332
|
-
writeFileSync(fname: string, data:
|
|
333
|
-
appendFile(fname: string, data:
|
|
334
|
-
appendFileSync(fname: string, data:
|
|
321
|
+
readFile(fname: string, flag: FileFlag, cred: Cred): Promise<Uint8Array>;
|
|
322
|
+
readFileSync(fname: string, flag: FileFlag, cred: Cred): Uint8Array;
|
|
323
|
+
writeFile(fname: string, data: Uint8Array, flag: FileFlag, mode: number, cred: Cred): Promise<void>;
|
|
324
|
+
writeFileSync(fname: string, data: Uint8Array, flag: FileFlag, mode: number, cred: Cred): void;
|
|
325
|
+
appendFile(fname: string, data: Uint8Array, flag: FileFlag, mode: number, cred: Cred): Promise<void>;
|
|
326
|
+
appendFileSync(fname: string, data: Uint8Array, flag: FileFlag, mode: number, cred: Cred): void;
|
|
335
327
|
chmod(p: string, mode: number, cred: Cred): Promise<void>;
|
|
336
328
|
chmodSync(p: string, mode: number, cred: Cred): void;
|
|
337
329
|
chown(p: string, new_uid: number, new_gid: number, cred: Cred): Promise<void>;
|
package/dist/filesystem.js
CHANGED
|
@@ -13,7 +13,7 @@ var _a;
|
|
|
13
13
|
import { ApiError, ErrorCode } from './ApiError.js';
|
|
14
14
|
import { FileFlag, ActionType } from './file.js';
|
|
15
15
|
import * as path from './emulation/path.js';
|
|
16
|
-
import {
|
|
16
|
+
import { encode } from './utils.js';
|
|
17
17
|
/**
|
|
18
18
|
* Structure for a filesystem. **All** ZenFS FileSystems must implement
|
|
19
19
|
* this.
|
|
@@ -317,7 +317,7 @@ export class BaseFileSystem extends FileSystem {
|
|
|
317
317
|
fd.closeSync();
|
|
318
318
|
}
|
|
319
319
|
}
|
|
320
|
-
readFile(fname,
|
|
320
|
+
readFile(fname, flag, cred) {
|
|
321
321
|
return __awaiter(this, void 0, void 0, function* () {
|
|
322
322
|
// Get file.
|
|
323
323
|
const fd = yield this.open(fname, flag, 0o644, cred);
|
|
@@ -327,17 +327,14 @@ export class BaseFileSystem extends FileSystem {
|
|
|
327
327
|
const buf = new Uint8Array(stat.size);
|
|
328
328
|
yield fd.read(buf, 0, stat.size, 0);
|
|
329
329
|
yield fd.close();
|
|
330
|
-
|
|
331
|
-
return buf;
|
|
332
|
-
}
|
|
333
|
-
return decode(buf);
|
|
330
|
+
return buf;
|
|
334
331
|
}
|
|
335
332
|
finally {
|
|
336
333
|
yield fd.close();
|
|
337
334
|
}
|
|
338
335
|
});
|
|
339
336
|
}
|
|
340
|
-
readFileSync(fname,
|
|
337
|
+
readFileSync(fname, flag, cred) {
|
|
341
338
|
// Get file.
|
|
342
339
|
const fd = this.openSync(fname, flag, 0o644, cred);
|
|
343
340
|
try {
|
|
@@ -346,16 +343,13 @@ export class BaseFileSystem extends FileSystem {
|
|
|
346
343
|
const buf = new Uint8Array(stat.size);
|
|
347
344
|
fd.readSync(buf, 0, stat.size, 0);
|
|
348
345
|
fd.closeSync();
|
|
349
|
-
|
|
350
|
-
return buf;
|
|
351
|
-
}
|
|
352
|
-
return decode(buf);
|
|
346
|
+
return buf;
|
|
353
347
|
}
|
|
354
348
|
finally {
|
|
355
349
|
fd.closeSync();
|
|
356
350
|
}
|
|
357
351
|
}
|
|
358
|
-
writeFile(fname, data,
|
|
352
|
+
writeFile(fname, data, flag, mode, cred) {
|
|
359
353
|
return __awaiter(this, void 0, void 0, function* () {
|
|
360
354
|
// Get file.
|
|
361
355
|
const fd = yield this.open(fname, flag, mode, cred);
|
|
@@ -371,7 +365,7 @@ export class BaseFileSystem extends FileSystem {
|
|
|
371
365
|
}
|
|
372
366
|
});
|
|
373
367
|
}
|
|
374
|
-
writeFileSync(fname, data,
|
|
368
|
+
writeFileSync(fname, data, flag, mode, cred) {
|
|
375
369
|
// Get file.
|
|
376
370
|
const fd = this.openSync(fname, flag, mode, cred);
|
|
377
371
|
try {
|
|
@@ -385,7 +379,7 @@ export class BaseFileSystem extends FileSystem {
|
|
|
385
379
|
fd.closeSync();
|
|
386
380
|
}
|
|
387
381
|
}
|
|
388
|
-
appendFile(fname, data,
|
|
382
|
+
appendFile(fname, data, flag, mode, cred) {
|
|
389
383
|
return __awaiter(this, void 0, void 0, function* () {
|
|
390
384
|
const fd = yield this.open(fname, flag, mode, cred);
|
|
391
385
|
try {
|
|
@@ -399,7 +393,7 @@ export class BaseFileSystem extends FileSystem {
|
|
|
399
393
|
}
|
|
400
394
|
});
|
|
401
395
|
}
|
|
402
|
-
appendFileSync(fname, data,
|
|
396
|
+
appendFileSync(fname, data, flag, mode, cred) {
|
|
403
397
|
const fd = this.openSync(fname, flag, mode, cred);
|
|
404
398
|
try {
|
|
405
399
|
if (typeof data === 'string') {
|
package/dist/utils.d.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import { FileSystem } from './filesystem.js';
|
|
6
6
|
import { Cred } from './cred.js';
|
|
7
7
|
import type { BaseBackendConstructor } from './backends/backend.js';
|
|
8
|
+
import type { TextEncoder as TextEncoderType, TextDecoder as TextDecoderType } from 'node:util';
|
|
8
9
|
/**
|
|
9
10
|
* Synchronous recursive makedir.
|
|
10
11
|
* @internal
|
|
@@ -30,12 +31,13 @@ export declare const setImmediate: (callback: () => unknown) => void;
|
|
|
30
31
|
* @internal
|
|
31
32
|
*/
|
|
32
33
|
export declare const ROOT_NODE_ID: string;
|
|
33
|
-
|
|
34
|
-
export declare const
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
declare const textEncoder: TextEncoderType;
|
|
35
|
+
export declare const encode: typeof textEncoder.encode;
|
|
36
|
+
declare const textDecoder: TextDecoderType;
|
|
37
|
+
export declare const decode: typeof textDecoder.decode;
|
|
37
38
|
/**
|
|
38
39
|
* Generates a random ID.
|
|
39
40
|
* @internal
|
|
40
41
|
*/
|
|
41
42
|
export declare function randomUUID(): string;
|
|
43
|
+
export {};
|
package/dist/utils.js
CHANGED
|
@@ -212,8 +212,10 @@ export const setImmediate = typeof globalThis.setImmediate == 'function' ? globa
|
|
|
212
212
|
* @internal
|
|
213
213
|
*/
|
|
214
214
|
export const ROOT_NODE_ID = '/';
|
|
215
|
-
|
|
216
|
-
export const
|
|
215
|
+
const textEncoder = new globalThis.TextEncoder();
|
|
216
|
+
export const encode = textEncoder.encode.bind(textEncoder);
|
|
217
|
+
const textDecoder = new globalThis.TextDecoder();
|
|
218
|
+
export const decode = textDecoder.decode.bind(textDecoder);
|
|
217
219
|
/**
|
|
218
220
|
* Generates a random ID.
|
|
219
221
|
* @internal
|