@zenfs/core 0.0.12 → 0.2.0
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/ApiError.d.ts +52 -15
- package/dist/ApiError.js +77 -50
- package/dist/FileIndex.d.ts +32 -35
- package/dist/FileIndex.js +93 -109
- package/dist/backends/AsyncMirror.d.ts +42 -43
- package/dist/backends/AsyncMirror.js +154 -147
- package/dist/backends/AsyncStore.d.ts +29 -28
- package/dist/backends/AsyncStore.js +375 -482
- package/dist/backends/FolderAdapter.js +8 -19
- package/dist/backends/InMemory.d.ts +16 -13
- package/dist/backends/InMemory.js +29 -14
- package/dist/backends/Locked.d.ts +8 -28
- package/dist/backends/Locked.js +74 -224
- package/dist/backends/OverlayFS.d.ts +26 -34
- package/dist/backends/OverlayFS.js +303 -511
- package/dist/backends/SyncStore.d.ts +54 -72
- package/dist/backends/SyncStore.js +159 -161
- package/dist/backends/backend.d.ts +45 -29
- package/dist/backends/backend.js +83 -13
- package/dist/backends/index.d.ts +6 -7
- package/dist/backends/index.js +5 -6
- package/dist/browser.min.js +21 -6
- package/dist/browser.min.js.map +4 -4
- package/dist/emulation/callbacks.d.ts +119 -113
- package/dist/emulation/callbacks.js +129 -92
- package/dist/emulation/constants.js +1 -1
- package/dist/emulation/dir.d.ts +55 -0
- package/dist/emulation/dir.js +104 -0
- package/dist/emulation/fs.d.ts +1 -2
- package/dist/emulation/fs.js +0 -1
- package/dist/emulation/index.d.ts +3 -0
- package/dist/emulation/index.js +3 -0
- package/dist/emulation/promises.d.ts +265 -145
- package/dist/emulation/promises.js +526 -383
- package/dist/emulation/shared.d.ts +20 -6
- package/dist/emulation/shared.js +22 -23
- package/dist/emulation/streams.d.ts +102 -0
- package/dist/emulation/streams.js +55 -0
- package/dist/emulation/sync.d.ts +98 -69
- package/dist/emulation/sync.js +280 -133
- package/dist/file.d.ts +175 -173
- package/dist/file.js +257 -273
- package/dist/filesystem.d.ts +71 -244
- package/dist/filesystem.js +67 -472
- package/dist/index.d.ts +7 -44
- package/dist/index.js +22 -75
- package/dist/inode.d.ts +37 -28
- package/dist/inode.js +123 -65
- package/dist/stats.d.ts +91 -36
- package/dist/stats.js +138 -110
- package/dist/utils.d.ts +26 -13
- package/dist/utils.js +79 -107
- package/package.json +7 -4
- package/readme.md +2 -40
package/dist/file.d.ts
CHANGED
|
@@ -1,26 +1,43 @@
|
|
|
1
|
-
import { Stats } from './stats.js';
|
|
2
|
-
import { FileSystem } from './filesystem.js';
|
|
1
|
+
import { Stats, type FileType } from './stats.js';
|
|
2
|
+
import { FileSystem, type SyncFileSystem } from './filesystem.js';
|
|
3
|
+
declare global {
|
|
4
|
+
interface ArrayBuffer {
|
|
5
|
+
readonly resizable: boolean;
|
|
6
|
+
readonly maxByteLength?: number;
|
|
7
|
+
resize(newLength: number): void;
|
|
8
|
+
}
|
|
9
|
+
interface SharedArrayBuffer {
|
|
10
|
+
readonly resizable: boolean;
|
|
11
|
+
readonly maxByteLength?: number;
|
|
12
|
+
resize(newLength: number): void;
|
|
13
|
+
}
|
|
14
|
+
interface ArrayBufferConstructor {
|
|
15
|
+
new (byteLength: number, options: {
|
|
16
|
+
maxByteLength?: number;
|
|
17
|
+
}): ArrayBuffer;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
3
20
|
export declare enum ActionType {
|
|
4
21
|
NOP = 0,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
22
|
+
THROW = 1,
|
|
23
|
+
TRUNCATE = 2,
|
|
24
|
+
CREATE = 3
|
|
8
25
|
}
|
|
9
26
|
/**
|
|
10
27
|
* Represents one of the following file flags. A convenience object.
|
|
11
28
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
29
|
+
* - r: Open file for reading. An exception occurs if the file does not exist.
|
|
30
|
+
* - r+: Open file for reading and writing. An exception occurs if the file does not exist.
|
|
31
|
+
* - rs: Open file for reading in synchronous mode. Instructs the filesystem to not cache writes.
|
|
32
|
+
* - rs+: Open file for reading and writing, and opens the file in synchronous mode.
|
|
33
|
+
* - w: Open file for writing. The file is created (if it does not exist) or truncated (if it exists).
|
|
34
|
+
* - wx: Like 'w' but opens the file in exclusive mode.
|
|
35
|
+
* - w+: Open file for reading and writing. The file is created (if it does not exist) or truncated (if it exists).
|
|
36
|
+
* - wx+: Like 'w+' but opens the file in exclusive mode.
|
|
37
|
+
* - a: Open file for appending. The file is created if it does not exist.
|
|
38
|
+
* - ax: Like 'a' but opens the file in exclusive mode.
|
|
39
|
+
* - a+: Open file for reading and appending. The file is created if it does not exist.
|
|
40
|
+
* - ax+: Like 'a+' but opens the file in exclusive mode.
|
|
24
41
|
*
|
|
25
42
|
* Exclusive mode ensures that the file path is newly created.
|
|
26
43
|
*/
|
|
@@ -29,27 +46,33 @@ export declare class FileFlag {
|
|
|
29
46
|
private static validFlagStrs;
|
|
30
47
|
/**
|
|
31
48
|
* Get an object representing the given file flag.
|
|
32
|
-
* @param
|
|
49
|
+
* @param flag The string or number representing the flag
|
|
33
50
|
* @return The FileFlag object representing the flag
|
|
34
51
|
* @throw when the flag string is invalid
|
|
35
52
|
*/
|
|
36
|
-
static
|
|
53
|
+
static FromString(flag: string | number): FileFlag;
|
|
37
54
|
private flagStr;
|
|
38
55
|
/**
|
|
39
56
|
* This should never be called directly.
|
|
40
|
-
* @param
|
|
41
|
-
* @throw when the
|
|
57
|
+
* @param flag The string or number representing the flag
|
|
58
|
+
* @throw when the flag is invalid
|
|
59
|
+
*/
|
|
60
|
+
constructor(flag: string | number);
|
|
61
|
+
/**
|
|
62
|
+
* @param flag The number representing the flag
|
|
63
|
+
* @return The string representing the flag
|
|
64
|
+
* @throw when the flag number is invalid
|
|
42
65
|
*/
|
|
43
|
-
|
|
66
|
+
static NumberToString(flag: number): string;
|
|
44
67
|
/**
|
|
45
68
|
* Get the underlying flag string for this flag.
|
|
46
69
|
*/
|
|
47
|
-
|
|
70
|
+
toString(): string;
|
|
48
71
|
/**
|
|
49
72
|
* Get the equivalent mode (0b0xxx: read, write, execute)
|
|
50
73
|
* Note: Execute will always be 0
|
|
51
74
|
*/
|
|
52
|
-
|
|
75
|
+
get mode(): number;
|
|
53
76
|
/**
|
|
54
77
|
* Returns true if the file is readable.
|
|
55
78
|
*/
|
|
@@ -85,45 +108,49 @@ export declare class FileFlag {
|
|
|
85
108
|
*/
|
|
86
109
|
pathNotExistsAction(): ActionType;
|
|
87
110
|
}
|
|
88
|
-
export
|
|
111
|
+
export declare abstract class File {
|
|
89
112
|
/**
|
|
90
|
-
*
|
|
113
|
+
* Get the current file position.
|
|
91
114
|
*/
|
|
92
|
-
|
|
115
|
+
abstract position?: number;
|
|
93
116
|
/**
|
|
94
|
-
*
|
|
117
|
+
* The path to the file
|
|
95
118
|
*/
|
|
96
|
-
|
|
119
|
+
abstract readonly path?: string;
|
|
97
120
|
/**
|
|
98
|
-
*
|
|
121
|
+
* Asynchronous `stat`.
|
|
99
122
|
*/
|
|
100
|
-
|
|
123
|
+
abstract stat(): Promise<Stats>;
|
|
101
124
|
/**
|
|
102
|
-
*
|
|
125
|
+
* Synchronous `stat`.
|
|
103
126
|
*/
|
|
104
|
-
|
|
127
|
+
abstract statSync(): Stats;
|
|
105
128
|
/**
|
|
106
|
-
*
|
|
129
|
+
* Asynchronous close.
|
|
107
130
|
*/
|
|
108
|
-
|
|
131
|
+
abstract close(): Promise<void>;
|
|
109
132
|
/**
|
|
110
|
-
*
|
|
133
|
+
* Synchronous close.
|
|
111
134
|
*/
|
|
112
|
-
|
|
135
|
+
abstract closeSync(): void;
|
|
113
136
|
/**
|
|
114
|
-
*
|
|
137
|
+
* Asynchronous truncate.
|
|
115
138
|
*/
|
|
116
|
-
|
|
139
|
+
abstract truncate(len: number): Promise<void>;
|
|
117
140
|
/**
|
|
118
|
-
*
|
|
141
|
+
* Synchronous truncate.
|
|
119
142
|
*/
|
|
120
|
-
|
|
143
|
+
abstract truncateSync(len: number): void;
|
|
121
144
|
/**
|
|
122
|
-
*
|
|
145
|
+
* Asynchronous sync.
|
|
123
146
|
*/
|
|
124
|
-
|
|
147
|
+
abstract sync(): Promise<void>;
|
|
148
|
+
/**
|
|
149
|
+
* Synchronous sync.
|
|
150
|
+
*/
|
|
151
|
+
abstract syncSync(): void;
|
|
125
152
|
/**
|
|
126
|
-
*
|
|
153
|
+
* Write buffer to the file.
|
|
127
154
|
* Note that it is unsafe to use fs.write multiple times on the same file
|
|
128
155
|
* without waiting for the callback.
|
|
129
156
|
* @param buffer Uint8Array containing the data to write to
|
|
@@ -135,9 +162,9 @@ export interface File {
|
|
|
135
162
|
* the current position.
|
|
136
163
|
* @returns Promise resolving to the new length of the buffer
|
|
137
164
|
*/
|
|
138
|
-
write(buffer: Uint8Array, offset
|
|
165
|
+
abstract write(buffer: Uint8Array, offset?: number, length?: number, position?: number): Promise<number>;
|
|
139
166
|
/**
|
|
140
|
-
*
|
|
167
|
+
* Write buffer to the file.
|
|
141
168
|
* Note that it is unsafe to use fs.writeSync multiple times on the same file
|
|
142
169
|
* without waiting for it to return.
|
|
143
170
|
* @param buffer Uint8Array containing the data to write to
|
|
@@ -148,9 +175,9 @@ export interface File {
|
|
|
148
175
|
* data should be written. If position is null, the data will be written at
|
|
149
176
|
* the current position.
|
|
150
177
|
*/
|
|
151
|
-
writeSync(buffer: Uint8Array, offset
|
|
178
|
+
abstract writeSync(buffer: Uint8Array, offset?: number, length?: number, position?: number): number;
|
|
152
179
|
/**
|
|
153
|
-
*
|
|
180
|
+
* Read data from the file.
|
|
154
181
|
* @param buffer The buffer that the data will be
|
|
155
182
|
* written to.
|
|
156
183
|
* @param offset The offset within the buffer where writing will
|
|
@@ -161,12 +188,12 @@ export interface File {
|
|
|
161
188
|
* position.
|
|
162
189
|
* @returns Promise resolving to the new length of the buffer
|
|
163
190
|
*/
|
|
164
|
-
read(buffer:
|
|
191
|
+
abstract read<TBuffer extends Uint8Array>(buffer: TBuffer, offset?: number, length?: number, position?: number): Promise<{
|
|
165
192
|
bytesRead: number;
|
|
166
|
-
buffer:
|
|
193
|
+
buffer: TBuffer;
|
|
167
194
|
}>;
|
|
168
195
|
/**
|
|
169
|
-
*
|
|
196
|
+
* Read data from the file.
|
|
170
197
|
* @param buffer The buffer that the data will be written to.
|
|
171
198
|
* @param offset The offset within the buffer where writing will start.
|
|
172
199
|
* @param length An integer specifying the number of bytes to read.
|
|
@@ -174,59 +201,53 @@ export interface File {
|
|
|
174
201
|
* in the file. If position is null, data will be read from the current file
|
|
175
202
|
* position.
|
|
176
203
|
*/
|
|
177
|
-
readSync(buffer: Uint8Array, offset
|
|
204
|
+
abstract readSync(buffer: Uint8Array, offset?: number, length?: number, position?: number): number;
|
|
178
205
|
/**
|
|
179
|
-
*
|
|
206
|
+
* Asynchronous `datasync`.
|
|
180
207
|
*
|
|
181
208
|
* Default implementation maps to `sync`.
|
|
182
209
|
*/
|
|
183
210
|
datasync(): Promise<void>;
|
|
184
211
|
/**
|
|
185
|
-
*
|
|
212
|
+
* Synchronous `datasync`.
|
|
186
213
|
*
|
|
187
214
|
* Default implementation maps to `syncSync`.
|
|
188
215
|
*/
|
|
189
216
|
datasyncSync(): void;
|
|
190
217
|
/**
|
|
191
|
-
*
|
|
218
|
+
* Asynchronous `chown`.
|
|
192
219
|
*/
|
|
193
|
-
chown(uid: number, gid: number): Promise<void>;
|
|
220
|
+
abstract chown(uid: number, gid: number): Promise<void>;
|
|
194
221
|
/**
|
|
195
|
-
*
|
|
222
|
+
* Synchronous `chown`.
|
|
196
223
|
*/
|
|
197
|
-
chownSync(uid: number, gid: number): void;
|
|
224
|
+
abstract chownSync(uid: number, gid: number): void;
|
|
198
225
|
/**
|
|
199
|
-
*
|
|
226
|
+
* Asynchronous `fchmod`.
|
|
200
227
|
*/
|
|
201
|
-
chmod(mode: number): Promise<void>;
|
|
228
|
+
abstract chmod(mode: number): Promise<void>;
|
|
202
229
|
/**
|
|
203
|
-
*
|
|
230
|
+
* Synchronous `fchmod`.
|
|
204
231
|
*/
|
|
205
|
-
chmodSync(mode: number): void;
|
|
232
|
+
abstract chmodSync(mode: number): void;
|
|
206
233
|
/**
|
|
207
|
-
*
|
|
234
|
+
* Change the file timestamps of the file.
|
|
208
235
|
*/
|
|
209
|
-
utimes(atime: Date, mtime: Date): Promise<void>;
|
|
236
|
+
abstract utimes(atime: Date, mtime: Date): Promise<void>;
|
|
210
237
|
/**
|
|
211
|
-
*
|
|
238
|
+
* Change the file timestamps of the file.
|
|
212
239
|
*/
|
|
213
|
-
utimesSync(atime: Date, mtime: Date): void;
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
chown(uid: number, gid: number): Promise<void>;
|
|
225
|
-
chownSync(uid: number, gid: number): void;
|
|
226
|
-
chmod(mode: number): Promise<void>;
|
|
227
|
-
chmodSync(mode: number): void;
|
|
228
|
-
utimes(atime: Date, mtime: Date): Promise<void>;
|
|
229
|
-
utimesSync(atime: Date, mtime: Date): void;
|
|
240
|
+
abstract utimesSync(atime: Date, mtime: Date): void;
|
|
241
|
+
/**
|
|
242
|
+
* Set the file type
|
|
243
|
+
* @internal
|
|
244
|
+
*/
|
|
245
|
+
abstract _setType(type: FileType): Promise<void>;
|
|
246
|
+
/**
|
|
247
|
+
* Set the file type
|
|
248
|
+
* @internal
|
|
249
|
+
*/
|
|
250
|
+
abstract _setTypeSync(type: FileType): void;
|
|
230
251
|
}
|
|
231
252
|
/**
|
|
232
253
|
* An implementation of the File interface that operates on a file that is
|
|
@@ -237,43 +258,45 @@ export declare class BaseFile {
|
|
|
237
258
|
* extend this class and implement those two methods.
|
|
238
259
|
* @todo 'close' lever that disables functionality once closed.
|
|
239
260
|
*/
|
|
240
|
-
export declare class PreloadFile<T extends FileSystem> extends
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
protected
|
|
245
|
-
|
|
261
|
+
export declare abstract class PreloadFile<T extends FileSystem> extends File {
|
|
262
|
+
/**
|
|
263
|
+
* The file system that created the file.
|
|
264
|
+
*/
|
|
265
|
+
protected fs: T;
|
|
266
|
+
/**
|
|
267
|
+
* Path to the file
|
|
268
|
+
*/
|
|
269
|
+
readonly path: string;
|
|
270
|
+
readonly flag: FileFlag;
|
|
271
|
+
readonly stats: Stats;
|
|
246
272
|
protected _buffer: Uint8Array;
|
|
273
|
+
protected _position: number;
|
|
247
274
|
protected _dirty: boolean;
|
|
248
275
|
/**
|
|
249
276
|
* Creates a file with the given path and, optionally, the given contents. Note
|
|
250
277
|
* that, if contents is specified, it will be mutated by the file!
|
|
251
|
-
* @param _fs The file system that created the file.
|
|
252
|
-
* @param _path
|
|
253
278
|
* @param _mode The mode that the file was opened using.
|
|
254
279
|
* Dictates permissions and where the file pointer starts.
|
|
255
|
-
* @param
|
|
280
|
+
* @param stats The stats object for the given file.
|
|
256
281
|
* PreloadFile will mutate this object. Note that this object must contain
|
|
257
282
|
* the appropriate mode that the file was opened as.
|
|
258
|
-
* @param
|
|
283
|
+
* @param buffer A buffer containing the entire
|
|
259
284
|
* contents of the file. PreloadFile will mutate this buffer. If not
|
|
260
285
|
* specified, we assume it is a new file.
|
|
261
286
|
*/
|
|
262
|
-
constructor(
|
|
287
|
+
constructor(
|
|
263
288
|
/**
|
|
264
|
-
*
|
|
289
|
+
* The file system that created the file.
|
|
265
290
|
*/
|
|
266
|
-
|
|
291
|
+
fs: T,
|
|
267
292
|
/**
|
|
268
|
-
*
|
|
293
|
+
* Path to the file
|
|
269
294
|
*/
|
|
270
|
-
|
|
271
|
-
getFlag(): FileFlag;
|
|
295
|
+
path: string, flag: FileFlag, stats: Stats, _buffer?: Uint8Array);
|
|
272
296
|
/**
|
|
273
|
-
* Get the
|
|
274
|
-
* @return [String] The path to the file.
|
|
297
|
+
* Get the underlying buffer for this file. Mutating not recommended and will mess up dirty tracking.
|
|
275
298
|
*/
|
|
276
|
-
|
|
299
|
+
get buffer(): Uint8Array;
|
|
277
300
|
/**
|
|
278
301
|
* Get the current file position.
|
|
279
302
|
*
|
|
@@ -281,42 +304,16 @@ export declare class PreloadFile<T extends FileSystem> extends BaseFile {
|
|
|
281
304
|
* > On Linux, positional writes don't work when the file is opened in append
|
|
282
305
|
* mode. The kernel ignores the position argument and always appends the data
|
|
283
306
|
* to the end of the file.
|
|
284
|
-
* @return
|
|
307
|
+
* @return The current file position.
|
|
285
308
|
*/
|
|
286
|
-
|
|
287
|
-
/**
|
|
288
|
-
* Advance the current file position by the indicated number of positions.
|
|
289
|
-
* @param [Number] delta
|
|
290
|
-
*/
|
|
291
|
-
advancePos(delta: number): number;
|
|
309
|
+
get position(): number;
|
|
292
310
|
/**
|
|
293
311
|
* Set the file position.
|
|
294
|
-
* @param
|
|
295
|
-
*/
|
|
296
|
-
setPos(newPos: number): number;
|
|
297
|
-
/**
|
|
298
|
-
* **Core**: Asynchronous sync. Must be implemented by subclasses of this
|
|
299
|
-
* class.
|
|
300
|
-
* @param [Function(ZenFS.ApiError)] cb
|
|
312
|
+
* @param newPos new position
|
|
301
313
|
*/
|
|
302
|
-
|
|
303
|
-
/**
|
|
304
|
-
* **Core**: Synchronous sync.
|
|
305
|
-
*/
|
|
306
|
-
syncSync(): void;
|
|
307
|
-
/**
|
|
308
|
-
* **Core**: Asynchronous close. Must be implemented by subclasses of this
|
|
309
|
-
* class.
|
|
310
|
-
* @param [Function(ZenFS.ApiError)] cb
|
|
311
|
-
*/
|
|
312
|
-
close(): Promise<void>;
|
|
313
|
-
/**
|
|
314
|
-
* **Core**: Synchronous close.
|
|
315
|
-
*/
|
|
316
|
-
closeSync(): void;
|
|
314
|
+
set position(newPos: number);
|
|
317
315
|
/**
|
|
318
316
|
* Asynchronous `stat`.
|
|
319
|
-
* @param [Function(ZenFS.ApiError, ZenFS.node.fs.Stats)] cb
|
|
320
317
|
*/
|
|
321
318
|
stat(): Promise<Stats>;
|
|
322
319
|
/**
|
|
@@ -325,111 +322,117 @@ export declare class PreloadFile<T extends FileSystem> extends BaseFile {
|
|
|
325
322
|
statSync(): Stats;
|
|
326
323
|
/**
|
|
327
324
|
* Asynchronous truncate.
|
|
328
|
-
* @param
|
|
329
|
-
* @param [Function(ZenFS.ApiError)] cb
|
|
325
|
+
* @param len
|
|
330
326
|
*/
|
|
331
327
|
truncate(len: number): Promise<void>;
|
|
332
328
|
/**
|
|
333
329
|
* Synchronous truncate.
|
|
334
|
-
* @param
|
|
330
|
+
* @param len
|
|
335
331
|
*/
|
|
336
332
|
truncateSync(len: number): void;
|
|
337
333
|
/**
|
|
338
334
|
* Write buffer to the file.
|
|
339
335
|
* Note that it is unsafe to use fs.write multiple times on the same file
|
|
340
336
|
* without waiting for the callback.
|
|
341
|
-
* @param
|
|
337
|
+
* @param buffer Uint8Array containing the data to write to
|
|
342
338
|
* the file.
|
|
343
|
-
* @param
|
|
344
|
-
* @param
|
|
345
|
-
* @param
|
|
339
|
+
* @param offset Offset in the buffer to start reading data from.
|
|
340
|
+
* @param length The amount of bytes to write to the file.
|
|
341
|
+
* @param position Offset from the beginning of the file where this
|
|
346
342
|
* data should be written. If position is null, the data will be written at
|
|
347
343
|
* the current position.
|
|
348
|
-
* @param [Function(ZenFS.ApiError, Number, ZenFS.node.Uint8Array)]
|
|
349
|
-
* cb The number specifies the number of bytes written into the file.
|
|
350
344
|
*/
|
|
351
|
-
write(buffer: Uint8Array, offset
|
|
345
|
+
write(buffer: Uint8Array, offset?: number, length?: number, position?: number): Promise<number>;
|
|
352
346
|
/**
|
|
353
347
|
* Write buffer to the file.
|
|
354
348
|
* Note that it is unsafe to use fs.writeSync multiple times on the same file
|
|
355
349
|
* without waiting for the callback.
|
|
356
|
-
* @param
|
|
350
|
+
* @param buffer Uint8Array containing the data to write to
|
|
357
351
|
* the file.
|
|
358
|
-
* @param
|
|
359
|
-
* @param
|
|
360
|
-
* @param
|
|
352
|
+
* @param offset Offset in the buffer to start reading data from.
|
|
353
|
+
* @param length The amount of bytes to write to the file.
|
|
354
|
+
* @param position Offset from the beginning of the file where this
|
|
361
355
|
* data should be written. If position is null, the data will be written at
|
|
362
356
|
* the current position.
|
|
363
|
-
* @
|
|
357
|
+
* @returns bytes written
|
|
364
358
|
*/
|
|
365
|
-
writeSync(buffer: Uint8Array, offset
|
|
359
|
+
writeSync(buffer: Uint8Array, offset?: number, length?: number, position?: number): number;
|
|
366
360
|
/**
|
|
367
361
|
* Read data from the file.
|
|
368
|
-
* @param
|
|
362
|
+
* @param buffer The buffer that the data will be
|
|
369
363
|
* written to.
|
|
370
|
-
* @param
|
|
364
|
+
* @param offset The offset within the buffer where writing will
|
|
371
365
|
* start.
|
|
372
|
-
* @param
|
|
373
|
-
* @param
|
|
366
|
+
* @param length An integer specifying the number of bytes to read.
|
|
367
|
+
* @param position An integer specifying where to begin reading from
|
|
374
368
|
* in the file. If position is null, data will be read from the current file
|
|
375
369
|
* position.
|
|
376
|
-
* @param [Function(ZenFS.ApiError, Number, ZenFS.node.Uint8Array)] cb The
|
|
377
|
-
* number is the number of bytes read
|
|
378
370
|
*/
|
|
379
|
-
read(buffer:
|
|
371
|
+
read<TBuffer extends Uint8Array>(buffer: TBuffer, offset?: number, length?: number, position?: number): Promise<{
|
|
380
372
|
bytesRead: number;
|
|
381
|
-
buffer:
|
|
373
|
+
buffer: TBuffer;
|
|
382
374
|
}>;
|
|
383
375
|
/**
|
|
384
376
|
* Read data from the file.
|
|
385
|
-
* @param
|
|
377
|
+
* @param buffer The buffer that the data will be
|
|
386
378
|
* written to.
|
|
387
|
-
* @param
|
|
388
|
-
*
|
|
389
|
-
* @param
|
|
390
|
-
* @param [Number] position An integer specifying where to begin reading from
|
|
379
|
+
* @param offset The offset within the buffer where writing will start.
|
|
380
|
+
* @param length An integer specifying the number of bytes to read.
|
|
381
|
+
* @param position An integer specifying where to begin reading from
|
|
391
382
|
* in the file. If position is null, data will be read from the current file
|
|
392
383
|
* position.
|
|
393
|
-
* @
|
|
384
|
+
* @returns number of bytes written
|
|
394
385
|
*/
|
|
395
|
-
readSync(buffer: Uint8Array, offset
|
|
386
|
+
readSync(buffer: Uint8Array, offset?: number, length?: number, position?: number): number;
|
|
396
387
|
/**
|
|
397
388
|
* Asynchronous `fchmod`.
|
|
398
|
-
* @param
|
|
389
|
+
* @param mode the mode
|
|
399
390
|
*/
|
|
400
391
|
chmod(mode: number): Promise<void>;
|
|
401
392
|
/**
|
|
402
393
|
* Synchronous `fchmod`.
|
|
403
|
-
* @param
|
|
394
|
+
* @param mode
|
|
404
395
|
*/
|
|
405
396
|
chmodSync(mode: number): void;
|
|
406
397
|
/**
|
|
407
398
|
* Asynchronous `fchown`.
|
|
408
|
-
* @param
|
|
409
|
-
* @param
|
|
399
|
+
* @param uid
|
|
400
|
+
* @param gid
|
|
410
401
|
*/
|
|
411
402
|
chown(uid: number, gid: number): Promise<void>;
|
|
412
403
|
/**
|
|
413
404
|
* Synchronous `fchown`.
|
|
414
|
-
* @param
|
|
415
|
-
* @param
|
|
405
|
+
* @param uid
|
|
406
|
+
* @param gid
|
|
416
407
|
*/
|
|
417
408
|
chownSync(uid: number, gid: number): void;
|
|
409
|
+
utimes(atime: Date, mtime: Date): Promise<void>;
|
|
410
|
+
utimesSync(atime: Date, mtime: Date): void;
|
|
418
411
|
protected isDirty(): boolean;
|
|
419
412
|
/**
|
|
420
413
|
* Resets the dirty bit. Should only be called after a sync has completed successfully.
|
|
421
414
|
*/
|
|
422
415
|
protected resetDirty(): void;
|
|
416
|
+
_setType(type: FileType): Promise<void>;
|
|
417
|
+
_setTypeSync(type: FileType): void;
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* For synchronous file systems
|
|
421
|
+
*/
|
|
422
|
+
export declare class SyncFile<FS extends SyncFileSystem> extends PreloadFile<FS> {
|
|
423
|
+
constructor(_fs: FS, _path: string, _flag: FileFlag, _stat: Stats, contents?: Uint8Array);
|
|
424
|
+
sync(): Promise<void>;
|
|
425
|
+
syncSync(): void;
|
|
426
|
+
close(): Promise<void>;
|
|
427
|
+
closeSync(): void;
|
|
423
428
|
}
|
|
424
429
|
/**
|
|
425
|
-
*
|
|
426
|
-
* Doesn't sync to anything, so it works nicely for memory-only files.
|
|
430
|
+
* For the filesystems which do not sync to anything..
|
|
427
431
|
*/
|
|
428
|
-
export declare class NoSyncFile<T extends FileSystem> extends PreloadFile<T>
|
|
432
|
+
export declare class NoSyncFile<T extends FileSystem> extends PreloadFile<T> {
|
|
429
433
|
constructor(_fs: T, _path: string, _flag: FileFlag, _stat: Stats, contents?: Uint8Array);
|
|
430
434
|
/**
|
|
431
435
|
* Asynchronous sync. Doesn't do anything, simply calls the cb.
|
|
432
|
-
* @param [Function(ZenFS.ApiError)] cb
|
|
433
436
|
*/
|
|
434
437
|
sync(): Promise<void>;
|
|
435
438
|
/**
|
|
@@ -438,7 +441,6 @@ export declare class NoSyncFile<T extends FileSystem> extends PreloadFile<T> imp
|
|
|
438
441
|
syncSync(): void;
|
|
439
442
|
/**
|
|
440
443
|
* Asynchronous close. Doesn't do anything, simply calls the cb.
|
|
441
|
-
* @param [Function(ZenFS.ApiError)] cb
|
|
442
444
|
*/
|
|
443
445
|
close(): Promise<void>;
|
|
444
446
|
/**
|