@zenfs/core 0.0.7 → 0.0.9

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.
@@ -90,10 +90,10 @@ export declare function open(path: string, flag: string, mode: number | string,
90
90
  * @option options [String] flag Defaults to `'r'`.
91
91
  * @param callback If no encoding is specified, then the raw buffer is returned.
92
92
  */
93
- export declare function readFile(filename: string, cb: BFSCallback<Buffer>): void;
93
+ export declare function readFile(filename: string, cb: BFSCallback<Uint8Array>): void;
94
94
  export declare function readFile(filename: string, options: {
95
95
  flag?: string;
96
- }, callback?: BFSCallback<Buffer>): void;
96
+ }, callback?: BFSCallback<Uint8Array>): void;
97
97
  export declare function readFile(filename: string, options: {
98
98
  encoding: string;
99
99
  flag?: string;
@@ -188,7 +188,7 @@ export declare function fdatasync(fd: number, cb?: BFSOneArgCallback): void;
188
188
  * Note that it is unsafe to use fs.write multiple times on the same file
189
189
  * without waiting for the callback.
190
190
  * @param fd
191
- * @param buffer Buffer containing the data to write to
191
+ * @param buffer Uint8Array containing the data to write to
192
192
  * the file.
193
193
  * @param offset Offset in the buffer to start reading data from.
194
194
  * @param length The amount of bytes to write to the file.
@@ -197,8 +197,8 @@ export declare function fdatasync(fd: number, cb?: BFSOneArgCallback): void;
197
197
  * the current position.
198
198
  * @param callback The number specifies the number of bytes written into the file.
199
199
  */
200
- export declare function write(fd: number, buffer: Buffer, offset: number, length: number, cb?: BFSThreeArgCallback<number, Buffer>): void;
201
- export declare function write(fd: number, buffer: Buffer, offset: number, length: number, position: number | null, cb?: BFSThreeArgCallback<number, Buffer>): void;
200
+ export declare function write(fd: number, buffer: Uint8Array, offset: number, length: number, cb?: BFSThreeArgCallback<number, Uint8Array>): void;
201
+ export declare function write(fd: number, buffer: Uint8Array, offset: number, length: number, position: number | null, cb?: BFSThreeArgCallback<number, Uint8Array>): void;
202
202
  export declare function write(fd: number, data: FileContents, cb?: BFSThreeArgCallback<number, string>): void;
203
203
  export declare function write(fd: number, data: FileContents, position: number | null, cb?: BFSThreeArgCallback<number, string>): void;
204
204
  export declare function write(fd: number, data: FileContents, position: number | null, encoding: BufferEncoding, cb?: BFSThreeArgCallback<number, string>): void;
@@ -214,7 +214,7 @@ export declare function write(fd: number, data: FileContents, position: number |
214
214
  * position.
215
215
  * @param callback The number is the number of bytes read
216
216
  */
217
- export declare function read(fd: number, buffer: Buffer, offset: number, length: number, position?: number, cb?: BFSThreeArgCallback<number, Buffer>): void;
217
+ export declare function read(fd: number, buffer: Uint8Array, offset: number, length: number, position?: number, cb?: BFSThreeArgCallback<number, Uint8Array>): void;
218
218
  /**
219
219
  * Asynchronous `fchown`.
220
220
  * @param fd
@@ -2,6 +2,7 @@ import { ApiError, ErrorCode } from '../ApiError.js';
2
2
  import { nop, normalizeMode } from './shared.js';
3
3
  import * as promises from './promises.js';
4
4
  import { R_OK } from './constants.js';
5
+ import { decode, encode } from '../utils.js';
5
6
  /**
6
7
  * Asynchronous rename. No arguments other than a possible exception are given
7
8
  * to the completion callback.
@@ -167,13 +168,13 @@ export function write(fd, arg2, arg3, arg4, arg5, cb = nop) {
167
168
  cb(new ApiError(ErrorCode.EINVAL, 'Invalid arguments.'));
168
169
  return;
169
170
  }
170
- buffer = Buffer.from(arg2, encoding);
171
+ buffer = encode(arg2);
171
172
  offset = 0;
172
173
  length = buffer.length;
173
174
  const _cb = cb;
174
175
  promises
175
176
  .write(fd, buffer, offset, length, position)
176
- .then(bytesWritten => _cb(null, bytesWritten, buffer.toString(encoding)))
177
+ .then(bytesWritten => _cb(null, bytesWritten, decode(buffer)))
177
178
  .catch(_cb);
178
179
  }
179
180
  else {
@@ -0,0 +1,16 @@
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ import type { ParsedPath } from 'node:path';
3
+ export declare const cwd = "/";
4
+ export declare const sep = "/";
5
+ export declare function normalizeString(path: string, allowAboveRoot: boolean): string;
6
+ export declare function formatExt(ext: string): string;
7
+ export declare function resolve(...args: string[]): string;
8
+ export declare function normalize(path: string): string;
9
+ export declare function isAbsolute(path: string): boolean;
10
+ export declare function join(...args: string[]): string;
11
+ export declare function relative(from: string, to: string): string;
12
+ export declare function dirname(path: string): string;
13
+ export declare function basename(path: string, suffix?: string): string;
14
+ export declare function extname(path: string): string;
15
+ export declare function format(pathObject: ParsedPath): string;
16
+ export declare function parse(path: string): ParsedPath;
@@ -0,0 +1,451 @@
1
+ /*
2
+ Copyright Joyent, Inc. and other Node contributors.
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a
5
+ copy of this software and associated documentation files (the
6
+ "Software"), to deal in the Software without restriction, including
7
+ without limitation the rights to use, copy, modify, merge, publish,
8
+ distribute, sublicense, and/or sell copies of the Software, and to permit
9
+ persons to whom the Software is furnished to do so, subject to the
10
+ following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included
13
+ in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
18
+ NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
19
+ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21
+ USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ */
23
+ export const cwd = '/';
24
+ export const sep = '/';
25
+ function validateString(str, name) {
26
+ if (typeof str != 'string') {
27
+ throw new TypeError(`"${name}" is not a string`);
28
+ }
29
+ }
30
+ function validateObject(str, name) {
31
+ if (typeof str != 'object') {
32
+ throw new TypeError(`"${name}" is not an object`);
33
+ }
34
+ }
35
+ // Resolves . and .. elements in a path with directory names
36
+ export function normalizeString(path, allowAboveRoot) {
37
+ let res = '';
38
+ let lastSegmentLength = 0;
39
+ let lastSlash = -1;
40
+ let dots = 0;
41
+ let char = '\x00';
42
+ for (let i = 0; i <= path.length; ++i) {
43
+ if (i < path.length) {
44
+ char = path[i];
45
+ }
46
+ else if (char == '/') {
47
+ break;
48
+ }
49
+ else {
50
+ char = '/';
51
+ }
52
+ if (char == '/') {
53
+ if (lastSlash === i - 1 || dots === 1) {
54
+ // NOOP
55
+ }
56
+ else if (dots === 2) {
57
+ if (res.length < 2 || lastSegmentLength !== 2 || res.at(-1) !== '.' || res.at(-2) !== '.') {
58
+ if (res.length > 2) {
59
+ const lastSlashIndex = res.lastIndexOf('/');
60
+ if (lastSlashIndex === -1) {
61
+ res = '';
62
+ lastSegmentLength = 0;
63
+ }
64
+ else {
65
+ res = res.slice(0, lastSlashIndex);
66
+ lastSegmentLength = res.length - 1 - res.lastIndexOf('/');
67
+ }
68
+ lastSlash = i;
69
+ dots = 0;
70
+ continue;
71
+ }
72
+ else if (res.length !== 0) {
73
+ res = '';
74
+ lastSegmentLength = 0;
75
+ lastSlash = i;
76
+ dots = 0;
77
+ continue;
78
+ }
79
+ }
80
+ if (allowAboveRoot) {
81
+ res += res.length > 0 ? '/..' : '..';
82
+ lastSegmentLength = 2;
83
+ }
84
+ }
85
+ else {
86
+ if (res.length > 0)
87
+ res += '/' + path.slice(lastSlash + 1, i);
88
+ else
89
+ res = path.slice(lastSlash + 1, i);
90
+ lastSegmentLength = i - lastSlash - 1;
91
+ }
92
+ lastSlash = i;
93
+ dots = 0;
94
+ }
95
+ else if (char === '.' && dots !== -1) {
96
+ ++dots;
97
+ }
98
+ else {
99
+ dots = -1;
100
+ }
101
+ }
102
+ return res;
103
+ }
104
+ export function formatExt(ext) {
105
+ return ext ? `${ext[0] === '.' ? '' : '.'}${ext}` : '';
106
+ }
107
+ export function resolve(...args) {
108
+ let resolvedPath = '';
109
+ let resolvedAbsolute = false;
110
+ for (let i = args.length - 1; i >= -1 && !resolvedAbsolute; i--) {
111
+ const path = i >= 0 ? args[i] : cwd;
112
+ validateString(path, `paths[${i}]`);
113
+ // Skip empty entries
114
+ if (path.length === 0) {
115
+ continue;
116
+ }
117
+ resolvedPath = `${path}/${resolvedPath}`;
118
+ resolvedAbsolute = path[0] === '/';
119
+ }
120
+ // At this point the path should be resolved to a full absolute path, but
121
+ // handle relative paths to be safe (might happen when process.cwd() fails)
122
+ // Normalize the path
123
+ resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute);
124
+ if (resolvedAbsolute) {
125
+ return `/${resolvedPath}`;
126
+ }
127
+ return resolvedPath.length > 0 ? resolvedPath : '.';
128
+ }
129
+ export function normalize(path) {
130
+ validateString(path, 'path');
131
+ if (path.length === 0)
132
+ return '.';
133
+ const isAbsolute = path[0] === '/';
134
+ const trailingSeparator = path.at(-1) === '/';
135
+ // Normalize the path
136
+ path = normalizeString(path, !isAbsolute);
137
+ if (path.length === 0) {
138
+ if (isAbsolute)
139
+ return '/';
140
+ return trailingSeparator ? './' : '.';
141
+ }
142
+ if (trailingSeparator)
143
+ path += '/';
144
+ return isAbsolute ? `/${path}` : path;
145
+ }
146
+ export function isAbsolute(path) {
147
+ validateString(path, 'path');
148
+ return path.length > 0 && path[0] === '/';
149
+ }
150
+ export function join(...args) {
151
+ if (args.length === 0)
152
+ return '.';
153
+ let joined;
154
+ for (let i = 0; i < args.length; ++i) {
155
+ const arg = args[i];
156
+ validateString(arg, 'path');
157
+ if (arg.length > 0) {
158
+ if (joined === undefined)
159
+ joined = arg;
160
+ else
161
+ joined += `/${arg}`;
162
+ }
163
+ }
164
+ if (joined === undefined)
165
+ return '.';
166
+ return normalize(joined);
167
+ }
168
+ export function relative(from, to) {
169
+ validateString(from, 'from');
170
+ validateString(to, 'to');
171
+ if (from === to)
172
+ return '';
173
+ // Trim leading forward slashes.
174
+ from = resolve(from);
175
+ to = resolve(to);
176
+ if (from === to)
177
+ return '';
178
+ const fromStart = 1;
179
+ const fromEnd = from.length;
180
+ const fromLen = fromEnd - fromStart;
181
+ const toStart = 1;
182
+ const toLen = to.length - toStart;
183
+ // Compare paths to find the longest common path from root
184
+ const length = fromLen < toLen ? fromLen : toLen;
185
+ let lastCommonSep = -1;
186
+ let i = 0;
187
+ for (; i < length; i++) {
188
+ const fromCode = from[fromStart + i];
189
+ if (fromCode !== to[toStart + i])
190
+ break;
191
+ else if (fromCode === '/')
192
+ lastCommonSep = i;
193
+ }
194
+ if (i === length) {
195
+ if (toLen > length) {
196
+ if (to[toStart + i] === '/') {
197
+ // We get here if `from` is the exact base path for `to`.
198
+ // For example: from='/foo/bar'; to='/foo/bar/baz'
199
+ return to.slice(toStart + i + 1);
200
+ }
201
+ if (i === 0) {
202
+ // We get here if `from` is the root
203
+ // For example: from='/'; to='/foo'
204
+ return to.slice(toStart + i);
205
+ }
206
+ }
207
+ else if (fromLen > length) {
208
+ if (from[fromStart + i] === '/') {
209
+ // We get here if `to` is the exact base path for `from`.
210
+ // For example: from='/foo/bar/baz'; to='/foo/bar'
211
+ lastCommonSep = i;
212
+ }
213
+ else if (i === 0) {
214
+ // We get here if `to` is the root.
215
+ // For example: from='/foo/bar'; to='/'
216
+ lastCommonSep = 0;
217
+ }
218
+ }
219
+ }
220
+ let out = '';
221
+ // Generate the relative path based on the path difference between `to`
222
+ // and `from`.
223
+ for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {
224
+ if (i === fromEnd || from[i] === '/') {
225
+ out += out.length === 0 ? '..' : '/..';
226
+ }
227
+ }
228
+ // Lastly, append the rest of the destination (`to`) path that comes after
229
+ // the common path parts.
230
+ return `${out}${to.slice(toStart + lastCommonSep)}`;
231
+ }
232
+ export function dirname(path) {
233
+ validateString(path, 'path');
234
+ if (path.length === 0)
235
+ return '.';
236
+ const hasRoot = path[0] === '/';
237
+ let end = -1;
238
+ let matchedSlash = true;
239
+ for (let i = path.length - 1; i >= 1; --i) {
240
+ if (path[i] === '/') {
241
+ if (!matchedSlash) {
242
+ end = i;
243
+ break;
244
+ }
245
+ }
246
+ else {
247
+ // We saw the first non-path separator
248
+ matchedSlash = false;
249
+ }
250
+ }
251
+ if (end === -1)
252
+ return hasRoot ? '/' : '.';
253
+ if (hasRoot && end === 1)
254
+ return '//';
255
+ return path.slice(0, end);
256
+ }
257
+ export function basename(path, suffix) {
258
+ if (suffix !== undefined)
259
+ validateString(suffix, 'ext');
260
+ validateString(path, 'path');
261
+ let start = 0;
262
+ let end = -1;
263
+ let matchedSlash = true;
264
+ if (suffix !== undefined && suffix.length > 0 && suffix.length <= path.length) {
265
+ if (suffix === path)
266
+ return '';
267
+ let extIdx = suffix.length - 1;
268
+ let firstNonSlashEnd = -1;
269
+ for (let i = path.length - 1; i >= 0; --i) {
270
+ if (path[i] === '/') {
271
+ // If we reached a path separator that was not part of a set of path
272
+ // separators at the end of the string, stop now
273
+ if (!matchedSlash) {
274
+ start = i + 1;
275
+ break;
276
+ }
277
+ }
278
+ else {
279
+ if (firstNonSlashEnd === -1) {
280
+ // We saw the first non-path separator, remember this index in case
281
+ // we need it if the extension ends up not matching
282
+ matchedSlash = false;
283
+ firstNonSlashEnd = i + 1;
284
+ }
285
+ if (extIdx >= 0) {
286
+ // Try to match the explicit extension
287
+ if (path[i] === suffix[extIdx]) {
288
+ if (--extIdx === -1) {
289
+ // We matched the extension, so mark this as the end of our path
290
+ // component
291
+ end = i;
292
+ }
293
+ }
294
+ else {
295
+ // Extension does not match, so our result is the entire path
296
+ // component
297
+ extIdx = -1;
298
+ end = firstNonSlashEnd;
299
+ }
300
+ }
301
+ }
302
+ }
303
+ if (start === end)
304
+ end = firstNonSlashEnd;
305
+ else if (end === -1)
306
+ end = path.length;
307
+ return path.slice(start, end);
308
+ }
309
+ for (let i = path.length - 1; i >= 0; --i) {
310
+ if (path[i] === '/') {
311
+ // If we reached a path separator that was not part of a set of path
312
+ // separators at the end of the string, stop now
313
+ if (!matchedSlash) {
314
+ start = i + 1;
315
+ break;
316
+ }
317
+ }
318
+ else if (end === -1) {
319
+ // We saw the first non-path separator, mark this as the end of our
320
+ // path component
321
+ matchedSlash = false;
322
+ end = i + 1;
323
+ }
324
+ }
325
+ if (end === -1)
326
+ return '';
327
+ return path.slice(start, end);
328
+ }
329
+ export function extname(path) {
330
+ validateString(path, 'path');
331
+ let startDot = -1;
332
+ let startPart = 0;
333
+ let end = -1;
334
+ let matchedSlash = true;
335
+ // Track the state of characters (if any) we see before our first dot and
336
+ // after any path separator we find
337
+ let preDotState = 0;
338
+ for (let i = path.length - 1; i >= 0; --i) {
339
+ if (path[i] === '/') {
340
+ // If we reached a path separator that was not part of a set of path
341
+ // separators at the end of the string, stop now
342
+ if (!matchedSlash) {
343
+ startPart = i + 1;
344
+ break;
345
+ }
346
+ continue;
347
+ }
348
+ if (end === -1) {
349
+ // We saw the first non-path separator, mark this as the end of our
350
+ // extension
351
+ matchedSlash = false;
352
+ end = i + 1;
353
+ }
354
+ if (path[i] === '.') {
355
+ // If this is our first dot, mark it as the start of our extension
356
+ if (startDot === -1)
357
+ startDot = i;
358
+ else if (preDotState !== 1)
359
+ preDotState = 1;
360
+ }
361
+ else if (startDot !== -1) {
362
+ // We saw a non-dot and non-path separator before our dot, so we should
363
+ // have a good chance at having a non-empty extension
364
+ preDotState = -1;
365
+ }
366
+ }
367
+ if (startDot === -1 ||
368
+ end === -1 ||
369
+ // We saw a non-dot character immediately before the dot
370
+ preDotState === 0 ||
371
+ // The (right-most) trimmed path component is exactly '..'
372
+ (preDotState === 1 && startDot === end - 1 && startDot === startPart + 1)) {
373
+ return '';
374
+ }
375
+ return path.slice(startDot, end);
376
+ }
377
+ export function format(pathObject) {
378
+ validateObject(pathObject, 'pathObject');
379
+ const dir = pathObject.dir || pathObject.root;
380
+ const base = pathObject.base || `${pathObject.name || ''}${formatExt(pathObject.ext)}`;
381
+ if (!dir) {
382
+ return base;
383
+ }
384
+ return dir === pathObject.root ? `${dir}${base}` : `${dir}/${base}`;
385
+ }
386
+ export function parse(path) {
387
+ validateString(path, 'path');
388
+ const isAbsolute = path[0] === '/';
389
+ const ret = { root: isAbsolute ? '/' : '', dir: '', base: '', ext: '', name: '' };
390
+ if (path.length === 0)
391
+ return ret;
392
+ const start = isAbsolute ? 1 : 0;
393
+ let startDot = -1;
394
+ let startPart = 0;
395
+ let end = -1;
396
+ let matchedSlash = true;
397
+ let i = path.length - 1;
398
+ // Track the state of characters (if any) we see before our first dot and
399
+ // after any path separator we find
400
+ let preDotState = 0;
401
+ // Get non-dir info
402
+ for (; i >= start; --i) {
403
+ if (path[i] === '/') {
404
+ // If we reached a path separator that was not part of a set of path
405
+ // separators at the end of the string, stop now
406
+ if (!matchedSlash) {
407
+ startPart = i + 1;
408
+ break;
409
+ }
410
+ continue;
411
+ }
412
+ if (end === -1) {
413
+ // We saw the first non-path separator, mark this as the end of our
414
+ // extension
415
+ matchedSlash = false;
416
+ end = i + 1;
417
+ }
418
+ if (path[i] === '.') {
419
+ // If this is our first dot, mark it as the start of our extension
420
+ if (startDot === -1)
421
+ startDot = i;
422
+ else if (preDotState !== 1)
423
+ preDotState = 1;
424
+ }
425
+ else if (startDot !== -1) {
426
+ // We saw a non-dot and non-path separator before our dot, so we should
427
+ // have a good chance at having a non-empty extension
428
+ preDotState = -1;
429
+ }
430
+ }
431
+ if (end !== -1) {
432
+ const start = startPart === 0 && isAbsolute ? 1 : startPart;
433
+ if (startDot === -1 ||
434
+ // We saw a non-dot character immediately before the dot
435
+ preDotState === 0 ||
436
+ // The (right-most) trimmed path component is exactly '..'
437
+ (preDotState === 1 && startDot === end - 1 && startDot === startPart + 1)) {
438
+ ret.base = ret.name = path.slice(start, end);
439
+ }
440
+ else {
441
+ ret.name = path.slice(start, startDot);
442
+ ret.base = path.slice(start, end);
443
+ ret.ext = path.slice(startDot, end);
444
+ }
445
+ }
446
+ if (startPart > 0)
447
+ ret.dir = path.slice(0, startPart - 1);
448
+ else if (isAbsolute)
449
+ ret.dir = '/';
450
+ return ret;
451
+ }
@@ -55,11 +55,11 @@ export declare function open(path: string, flag: string, mode?: number | string)
55
55
  * @param options
56
56
  * @option options [String] encoding The string encoding for the file contents. Defaults to `null`.
57
57
  * @option options [String] flag Defaults to `'r'`.
58
- * @return [String | ZenFS.node.Buffer]
58
+ * @return [String | ZenFS.node.Uint8Array]
59
59
  */
60
60
  export declare function readFile(filename: string, options?: {
61
61
  flag?: string;
62
- }): Promise<Buffer>;
62
+ }): Promise<Uint8Array>;
63
63
  export declare function readFile(filename: string, options: {
64
64
  encoding: string;
65
65
  flag?: string;
@@ -144,7 +144,7 @@ export declare function fdatasync(fd: number): Promise<void>;
144
144
  * Note that it is unsafe to use fs.write multiple times on the same file
145
145
  * without waiting for it to return.
146
146
  * @param fd
147
- * @param buffer Buffer containing the data to write to
147
+ * @param buffer Uint8Array containing the data to write to
148
148
  * the file.
149
149
  * @param offset Offset in the buffer to start reading data from.
150
150
  * @param length The amount of bytes to write to the file.
@@ -152,7 +152,7 @@ export declare function fdatasync(fd: number): Promise<void>;
152
152
  * data should be written. If position is null, the data will be written at
153
153
  * the current position.
154
154
  */
155
- export declare function write(fd: number, buffer: Buffer, offset: number, length: number, position?: number): Promise<number>;
155
+ export declare function write(fd: number, buffer: Uint8Array, offset: number, length: number, position?: number): Promise<number>;
156
156
  export declare function write(fd: number, data: string, position?: number | null, encoding?: BufferEncoding): Promise<number>;
157
157
  /**
158
158
  * Read data from the file specified by `fd`.
@@ -166,9 +166,9 @@ export declare function write(fd: number, data: string, position?: number | null
166
166
  * in the file. If position is null, data will be read from the current file
167
167
  * position.
168
168
  */
169
- export declare function read(fd: number, buffer: Buffer, offset: number, length: number, position?: number): Promise<{
169
+ export declare function read(fd: number, buffer: Uint8Array, offset: number, length: number, position?: number): Promise<{
170
170
  bytesRead: number;
171
- buffer: Buffer;
171
+ buffer: Uint8Array;
172
172
  }>;
173
173
  /**
174
174
  * `fchown`.
@@ -12,6 +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
16
  /**
16
17
  * Utility for FS ops. It handles
17
18
  * - path normalization (for the first parameter to the FS op)
@@ -234,7 +235,7 @@ export function write(fd, arg2, arg3, arg4, arg5) {
234
235
  position = typeof arg3 === 'number' ? arg3 : null;
235
236
  const encoding = (typeof arg4 === 'string' ? arg4 : 'utf8');
236
237
  offset = 0;
237
- buffer = Buffer.from(arg2, encoding);
238
+ buffer = encode(arg2);
238
239
  length = buffer.length;
239
240
  }
240
241
  else {
@@ -1,5 +1,5 @@
1
1
  // Utilities and shared data
2
- import { posix as path } from 'path';
2
+ import { resolve } from './path.js';
3
3
  import { ApiError, ErrorCode } from '../ApiError.js';
4
4
  import { Cred } from '../cred.js';
5
5
  //import { BackendConstructor } from '../backends.js';
@@ -52,7 +52,7 @@ export function normalizePath(p) {
52
52
  throw new ApiError(ErrorCode.EINVAL, 'Path must not be empty.');
53
53
  }
54
54
  p = p.replaceAll(/\/+/g, '/');
55
- return path.resolve(p);
55
+ return resolve(p);
56
56
  }
57
57
  export function normalizeOptions(options, defEnc, defFlag, defMode) {
58
58
  // typeof null === 'object' so special-case handing is needed.
@@ -129,7 +129,7 @@ export function mount(mountPoint, fs) {
129
129
  if (mountPoint[0] !== '/') {
130
130
  mountPoint = '/' + mountPoint;
131
131
  }
132
- mountPoint = path.resolve(mountPoint);
132
+ mountPoint = resolve(mountPoint);
133
133
  if (mounts.has(mountPoint)) {
134
134
  throw new ApiError(ErrorCode.EINVAL, 'Mount point ' + mountPoint + ' is already in use.');
135
135
  }
@@ -142,7 +142,7 @@ export function umount(mountPoint) {
142
142
  if (mountPoint[0] !== '/') {
143
143
  mountPoint = `/${mountPoint}`;
144
144
  }
145
- mountPoint = path.resolve(mountPoint);
145
+ mountPoint = resolve(mountPoint);
146
146
  if (!mounts.has(mountPoint)) {
147
147
  throw new ApiError(ErrorCode.EINVAL, 'Mount point ' + mountPoint + ' is already unmounted.');
148
148
  }
@@ -54,11 +54,11 @@ export declare function openSync(path: string, flag: string, mode?: number | str
54
54
  * @param options
55
55
  * @option options [String] encoding The string encoding for the file contents. Defaults to `null`.
56
56
  * @option options [String] flag Defaults to `'r'`.
57
- * @return [String | ZenFS.node.Buffer]
57
+ * @return [String | ZenFS.node.Uint8Array]
58
58
  */
59
59
  export declare function readFileSync(filename: string, options?: {
60
60
  flag?: string;
61
- }): Buffer;
61
+ }): Uint8Array;
62
62
  export declare function readFileSync(filename: string, options: {
63
63
  encoding: string;
64
64
  flag?: string;
@@ -138,7 +138,7 @@ export declare function fdatasyncSync(fd: number): void;
138
138
  * Note that it is unsafe to use fs.write multiple times on the same file
139
139
  * without waiting for it to return.
140
140
  * @param fd
141
- * @param buffer Buffer containing the data to write to
141
+ * @param buffer Uint8Array containing the data to write to
142
142
  * the file.
143
143
  * @param offset Offset in the buffer to start reading data from.
144
144
  * @param length The amount of bytes to write to the file.
@@ -146,7 +146,7 @@ export declare function fdatasyncSync(fd: number): void;
146
146
  * data should be written. If position is null, the data will be written at
147
147
  * the current position.
148
148
  */
149
- export declare function writeSync(fd: number, buffer: Buffer, offset: number, length: number, position?: number | null): number;
149
+ export declare function writeSync(fd: number, buffer: Uint8Array, offset: number, length: number, position?: number | null): number;
150
150
  export declare function writeSync(fd: number, data: string, position?: number | null, encoding?: BufferEncoding): number;
151
151
  /**
152
152
  * Read data from the file specified by `fd`.
@@ -160,8 +160,8 @@ export declare function writeSync(fd: number, data: string, position?: number |
160
160
  * in the file. If position is null, data will be read from the current file
161
161
  * position.
162
162
  */
163
- export declare function readSync(fd: number, buffer: Buffer, opts?: ReadSyncOptions): number;
164
- export declare function readSync(fd: number, buffer: Buffer, offset: number, length: number, position?: number): number;
163
+ export declare function readSync(fd: number, buffer: Uint8Array, opts?: ReadSyncOptions): number;
164
+ export declare function readSync(fd: number, buffer: Uint8Array, offset: number, length: number, position?: number): number;
165
165
  /**
166
166
  * Synchronous `fchown`.
167
167
  * @param fd