@depup/jsonjoy.com__fs-node-to-fsa 4.56.11-depup.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.
@@ -0,0 +1,37 @@
1
+ import { NodePermissionStatus } from './NodePermissionStatus';
2
+ import type { IFileSystemHandle, FileSystemHandlePermissionDescriptor } from '@jsonjoy.com/fs-fsa';
3
+ import type { NodeFsaFs, NodeFsaContext } from './types';
4
+ /**
5
+ * Represents a File System Access API file handle `FileSystemHandle` object,
6
+ * which was created from a Node.js `fs` module.
7
+ *
8
+ * @see [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/FileSystemHandle)
9
+ */
10
+ export declare abstract class NodeFileSystemHandle implements IFileSystemHandle {
11
+ readonly kind: 'file' | 'directory';
12
+ readonly name: string;
13
+ protected abstract readonly fs: NodeFsaFs;
14
+ protected abstract readonly __path: string;
15
+ protected abstract readonly ctx: NodeFsaContext;
16
+ constructor(kind: 'file' | 'directory', name: string);
17
+ /**
18
+ * Compares two handles to see if the associated entries (either a file or directory) match.
19
+ *
20
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemHandle/isSameEntry
21
+ */
22
+ isSameEntry(fileSystemHandle: IFileSystemHandle): boolean;
23
+ /**
24
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemHandle/queryPermission
25
+ */
26
+ queryPermission(fileSystemHandlePermissionDescriptor: FileSystemHandlePermissionDescriptor): Promise<NodePermissionStatus>;
27
+ /**
28
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemHandle/remove
29
+ */
30
+ remove({ recursive }?: {
31
+ recursive?: boolean;
32
+ }): Promise<void>;
33
+ /**
34
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemHandle/requestPermission
35
+ */
36
+ requestPermission(fileSystemHandlePermissionDescriptor: FileSystemHandlePermissionDescriptor): NodePermissionStatus;
37
+ }
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NodeFileSystemHandle = void 0;
4
+ const NodePermissionStatus_1 = require("./NodePermissionStatus");
5
+ /**
6
+ * Represents a File System Access API file handle `FileSystemHandle` object,
7
+ * which was created from a Node.js `fs` module.
8
+ *
9
+ * @see [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/FileSystemHandle)
10
+ */
11
+ class NodeFileSystemHandle {
12
+ constructor(kind, name) {
13
+ this.kind = kind;
14
+ this.name = name;
15
+ }
16
+ /**
17
+ * Compares two handles to see if the associated entries (either a file or directory) match.
18
+ *
19
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemHandle/isSameEntry
20
+ */
21
+ isSameEntry(fileSystemHandle) {
22
+ return (this.constructor === fileSystemHandle.constructor && this.__path === fileSystemHandle.__path);
23
+ }
24
+ /**
25
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemHandle/queryPermission
26
+ */
27
+ async queryPermission(fileSystemHandlePermissionDescriptor) {
28
+ const { mode } = fileSystemHandlePermissionDescriptor;
29
+ // Check if the requested mode is compatible with the context mode
30
+ const requestedMode = mode;
31
+ const contextMode = this.ctx.mode;
32
+ // If requesting readwrite but context only allows read, deny
33
+ if (requestedMode === 'readwrite' && contextMode === 'read') {
34
+ return new NodePermissionStatus_1.NodePermissionStatus(requestedMode, 'denied');
35
+ }
36
+ try {
37
+ // Use Node.js fs.promises.access() to check permissions asynchronously
38
+ let accessMode = 0 /* AMODE.F_OK */;
39
+ if (mode === 'read') {
40
+ accessMode = 4 /* AMODE.R_OK */;
41
+ }
42
+ else if (mode === 'readwrite') {
43
+ accessMode = 4 /* AMODE.R_OK */ | 2 /* AMODE.W_OK */;
44
+ }
45
+ // Use asynchronous access check
46
+ await this.fs.promises.access(this.__path, accessMode);
47
+ return new NodePermissionStatus_1.NodePermissionStatus(mode, 'granted');
48
+ }
49
+ catch (error) {
50
+ // If access check fails, permission is denied
51
+ return new NodePermissionStatus_1.NodePermissionStatus(mode, 'denied');
52
+ }
53
+ }
54
+ /**
55
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemHandle/remove
56
+ */
57
+ async remove({ recursive } = { recursive: false }) {
58
+ throw new Error('Not implemented');
59
+ }
60
+ /**
61
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemHandle/requestPermission
62
+ */
63
+ requestPermission(fileSystemHandlePermissionDescriptor) {
64
+ throw new Error('Not implemented');
65
+ }
66
+ }
67
+ exports.NodeFileSystemHandle = NodeFileSystemHandle;
68
+ //# sourceMappingURL=NodeFileSystemHandle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NodeFileSystemHandle.js","sourceRoot":"","sources":["../src/NodeFileSystemHandle.ts"],"names":[],"mappings":";;;AACA,iEAA8D;AAI9D;;;;;GAKG;AACH,MAAsB,oBAAoB;IAKxC,YACkB,IAA0B,EAC1B,IAAY;QADZ,SAAI,GAAJ,IAAI,CAAsB;QAC1B,SAAI,GAAJ,IAAI,CAAQ;IAC3B,CAAC;IAEJ;;;;OAIG;IACI,WAAW,CAAC,gBAAmC;QACpD,OAAO,CACL,IAAI,CAAC,WAAW,KAAK,gBAAgB,CAAC,WAAW,IAAK,IAAY,CAAC,MAAM,KAAM,gBAAwB,CAAC,MAAM,CAC/G,CAAC;IACJ,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,eAAe,CAC1B,oCAA0E;QAE1E,MAAM,EAAE,IAAI,EAAE,GAAG,oCAAoC,CAAC;QAEtD,kEAAkE;QAClE,MAAM,aAAa,GAAG,IAAI,CAAC;QAC3B,MAAM,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC;QAElC,6DAA6D;QAC7D,IAAI,aAAa,KAAK,WAAW,IAAI,WAAW,KAAK,MAAM,EAAE,CAAC;YAC5D,OAAO,IAAI,2CAAoB,CAAC,aAAa,EAAE,QAAQ,CAAC,CAAC;QAC3D,CAAC;QAED,IAAI,CAAC;YACH,uEAAuE;YACvE,IAAI,UAAU,qBAAa,CAAC;YAE5B,IAAI,IAAI,KAAK,MAAM,EAAE,CAAC;gBACpB,UAAU,qBAAa,CAAC;YAC1B,CAAC;iBAAM,IAAI,IAAI,KAAK,WAAW,EAAE,CAAC;gBAChC,UAAU,GAAG,uCAAuB,CAAC;YACvC,CAAC;YAED,gCAAgC;YAChC,MAAM,IAAI,CAAC,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;YAEvD,OAAO,IAAI,2CAAoB,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;QACnD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,8CAA8C;YAC9C,OAAO,IAAI,2CAAoB,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;QAClD,CAAC;IACH,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,MAAM,CAAC,EAAE,SAAS,KAA8B,EAAE,SAAS,EAAE,KAAK,EAAE;QAC/E,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACrC,CAAC;IAED;;OAEG;IACI,iBAAiB,CACtB,oCAA0E;QAE1E,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACrC,CAAC;CACF;AAzED,oDAyEC"}
@@ -0,0 +1,42 @@
1
+ import type { FileSystemReadWriteOptions, IFileSystemSyncAccessHandle } from '@jsonjoy.com/fs-fsa';
2
+ import type { NodeFsaContext, NodeFsaFs } from './types';
3
+ /**
4
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemSyncAccessHandle
5
+ */
6
+ export declare class NodeFileSystemSyncAccessHandle implements IFileSystemSyncAccessHandle {
7
+ protected readonly fs: NodeFsaFs;
8
+ protected readonly path: string;
9
+ protected readonly ctx: NodeFsaContext;
10
+ protected readonly fd: number;
11
+ constructor(fs: NodeFsaFs, path: string, ctx: NodeFsaContext);
12
+ /**
13
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemSyncAccessHandle/close
14
+ */
15
+ close(): Promise<void>;
16
+ /**
17
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemSyncAccessHandle/flush
18
+ */
19
+ flush(): Promise<void>;
20
+ /**
21
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemSyncAccessHandle/getSize
22
+ */
23
+ getSize(): Promise<number>;
24
+ /**
25
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemSyncAccessHandle/read
26
+ */
27
+ read(buffer: ArrayBuffer | ArrayBufferView, options?: FileSystemReadWriteOptions): Promise<number>;
28
+ /**
29
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemSyncAccessHandle/truncate
30
+ * @param newSize The number of bytes to resize the file to.
31
+ */
32
+ truncate(newSize: number): Promise<void>;
33
+ /**
34
+ * Writes the content of a specified buffer to the file associated with the
35
+ * handle, optionally at a given offset.
36
+ *
37
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemSyncAccessHandle/write
38
+ * @param buffer
39
+ * @param options
40
+ */
41
+ write(buffer: ArrayBuffer | ArrayBufferView | DataView, options?: FileSystemReadWriteOptions): Promise<number>;
42
+ }
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NodeFileSystemSyncAccessHandle = void 0;
4
+ const util_1 = require("./util");
5
+ const buffer_1 = require("@jsonjoy.com/fs-node-builtins/lib/internal/buffer");
6
+ /**
7
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemSyncAccessHandle
8
+ */
9
+ class NodeFileSystemSyncAccessHandle {
10
+ constructor(fs, path, ctx) {
11
+ this.fs = fs;
12
+ this.path = path;
13
+ this.ctx = ctx;
14
+ this.fd = fs.openSync(path, 'r+');
15
+ this.ctx.locks.acquireLock(this.path);
16
+ }
17
+ /**
18
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemSyncAccessHandle/close
19
+ */
20
+ async close() {
21
+ (0, util_1.assertCanWrite)(this.ctx.mode);
22
+ this.fs.closeSync(this.fd);
23
+ this.ctx.locks.releaseLock(this.path);
24
+ }
25
+ /**
26
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemSyncAccessHandle/flush
27
+ */
28
+ async flush() {
29
+ (0, util_1.assertCanWrite)(this.ctx.mode);
30
+ this.fs.fsyncSync(this.fd);
31
+ }
32
+ /**
33
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemSyncAccessHandle/getSize
34
+ */
35
+ async getSize() {
36
+ return this.fs.statSync(this.path).size;
37
+ }
38
+ /**
39
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemSyncAccessHandle/read
40
+ */
41
+ async read(buffer, options = {}) {
42
+ const buf = buffer instanceof ArrayBuffer ? buffer_1.Buffer.from(buffer) : buffer;
43
+ try {
44
+ const size = this.fs.readSync(this.fd, buf, 0, buffer.byteLength, options.at ?? 0);
45
+ return size;
46
+ }
47
+ catch (error) {
48
+ if (error instanceof DOMException)
49
+ throw error;
50
+ if (error && typeof error === 'object') {
51
+ switch (error.code) {
52
+ case 'EBADF': {
53
+ throw new DOMException('File handle already closed.', 'InvalidStateError');
54
+ }
55
+ }
56
+ }
57
+ throw error;
58
+ }
59
+ }
60
+ /**
61
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemSyncAccessHandle/truncate
62
+ * @param newSize The number of bytes to resize the file to.
63
+ */
64
+ async truncate(newSize) {
65
+ (0, util_1.assertCanWrite)(this.ctx.mode);
66
+ this.fs.truncateSync(this.fd, newSize);
67
+ }
68
+ /**
69
+ * Writes the content of a specified buffer to the file associated with the
70
+ * handle, optionally at a given offset.
71
+ *
72
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemSyncAccessHandle/write
73
+ * @param buffer
74
+ * @param options
75
+ */
76
+ async write(buffer, options = {}) {
77
+ (0, util_1.assertCanWrite)(this.ctx.mode);
78
+ const buf = buffer instanceof ArrayBuffer ? buffer_1.Buffer.from(buffer) : buffer;
79
+ try {
80
+ return this.fs.writeSync(this.fd, buf, 0, buffer.byteLength, options.at ?? 0);
81
+ }
82
+ catch (error) {
83
+ if (error instanceof DOMException)
84
+ throw error;
85
+ if (error && typeof error === 'object') {
86
+ switch (error.code) {
87
+ case 'EBADF': {
88
+ throw new DOMException('File handle already closed.', 'InvalidStateError');
89
+ }
90
+ }
91
+ }
92
+ throw error;
93
+ }
94
+ }
95
+ }
96
+ exports.NodeFileSystemSyncAccessHandle = NodeFileSystemSyncAccessHandle;
97
+ //# sourceMappingURL=NodeFileSystemSyncAccessHandle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NodeFileSystemSyncAccessHandle.js","sourceRoot":"","sources":["../src/NodeFileSystemSyncAccessHandle.ts"],"names":[],"mappings":";;;AAAA,iCAAwC;AACxC,8EAA2E;AAI3E;;GAEG;AACH,MAAa,8BAA8B;IAGzC,YACqB,EAAa,EACb,IAAY,EACZ,GAAmB;QAFnB,OAAE,GAAF,EAAE,CAAW;QACb,SAAI,GAAJ,IAAI,CAAQ;QACZ,QAAG,GAAH,GAAG,CAAgB;QAEtC,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAClC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACxC,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,KAAK;QAChB,IAAA,qBAAc,EAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC9B,IAAI,CAAC,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC3B,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACxC,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,KAAK;QAChB,IAAA,qBAAc,EAAC,IAAI,CAAC,GAAG,CAAC,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,CAAC,CAAC;IACzC,CAAC;IAED;;;;;;;OAOG;IACI,KAAK,CAAC,KAAK,CAChB,MAAgD,EAChD,UAAsC,EAAE;QAExC,IAAA,qBAAc,EAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC9B,MAAM,GAAG,GAA6B,MAAM,YAAY,WAAW,CAAC,CAAC,CAAC,eAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;QACnG,IAAI,CAAC;YACH,OAAO,IAAI,CAAC,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,MAAM,CAAC,UAAU,EAAE,OAAO,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC;QAChF,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,KAAK,YAAY,YAAY;gBAAE,MAAM,KAAK,CAAC;YAC/C,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;gBACvC,QAAQ,KAAK,CAAC,IAAI,EAAE,CAAC;oBACnB,KAAK,OAAO,CAAC,CAAC,CAAC;wBACb,MAAM,IAAI,YAAY,CAAC,6BAA6B,EAAE,mBAAmB,CAAC,CAAC;oBAC7E,CAAC;gBACH,CAAC;YACH,CAAC;YACD,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;CACF;AA9FD,wEA8FC"}
@@ -0,0 +1,56 @@
1
+ import type { Data, FileSystemWritableFileStreamParams, IFileSystemWritableFileStream } from '@jsonjoy.com/fs-fsa';
2
+ import type { IFileHandle } from '@jsonjoy.com/fs-node-utils/lib/types/misc';
3
+ import type { NodeFsaFs, NodeFsaContext } from './types';
4
+ /**
5
+ * When Chrome writes to the file, it creates a copy of the file with extension
6
+ * `.crswap` and then replaces the original file with the copy only when the
7
+ * `close()` method is called. If the `abort()` method is called, the `.crswap`
8
+ * file is deleted.
9
+ *
10
+ * If a file name with with extension `.crswap` is already taken, it
11
+ * creates a new swap file with extension `.1.crswap` and so on.
12
+ */
13
+ export declare const createSwapFile: (fs: NodeFsaFs, path: string, keepExistingData: boolean) => Promise<[handle: IFileHandle, path: string]>;
14
+ interface SwapFile {
15
+ /** Swap file full path name. */
16
+ path: string;
17
+ /** Seek offset in the file. */
18
+ offset: number;
19
+ /** Node.js open FileHandle. */
20
+ handle?: IFileHandle;
21
+ /** Resolves when swap file is ready for operations. */
22
+ ready?: Promise<void>;
23
+ }
24
+ declare const WS: typeof WritableStream;
25
+ /**
26
+ * Is a WritableStream object with additional convenience methods, which
27
+ * operates on a single file on disk. The interface is accessed through the
28
+ * `FileSystemFileHandle.createWritable()` method.
29
+ *
30
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemWritableFileStream
31
+ */
32
+ export declare class NodeFileSystemWritableFileStream extends WS implements IFileSystemWritableFileStream {
33
+ protected readonly fs: NodeFsaFs;
34
+ protected readonly path: string;
35
+ protected readonly ctx: NodeFsaContext;
36
+ protected readonly swap: SwapFile;
37
+ constructor(fs: NodeFsaFs, path: string, keepExistingData: boolean, ctx: NodeFsaContext);
38
+ /**
39
+ * @sse https://developer.mozilla.org/en-US/docs/Web/API/FileSystemWritableFileStream/seek
40
+ * @param position An `unsigned long` describing the byte position from the top
41
+ * (beginning) of the file.
42
+ */
43
+ seek(position: number): Promise<void>;
44
+ /**
45
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemWritableFileStream/truncate
46
+ * @param size An `unsigned long` of the amount of bytes to resize the stream to.
47
+ */
48
+ truncate(size: number): Promise<void>;
49
+ protected writeBase(chunk: Data): Promise<void>;
50
+ /**
51
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemWritableFileStream/write
52
+ */
53
+ write(chunk: Data): Promise<void>;
54
+ write(params: FileSystemWritableFileStreamParams): Promise<void>;
55
+ }
56
+ export {};
@@ -0,0 +1,191 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NodeFileSystemWritableFileStream = exports.createSwapFile = void 0;
4
+ const buffer_1 = require("@jsonjoy.com/fs-node-builtins/lib/internal/buffer");
5
+ const util_1 = require("./util");
6
+ /**
7
+ * When Chrome writes to the file, it creates a copy of the file with extension
8
+ * `.crswap` and then replaces the original file with the copy only when the
9
+ * `close()` method is called. If the `abort()` method is called, the `.crswap`
10
+ * file is deleted.
11
+ *
12
+ * If a file name with with extension `.crswap` is already taken, it
13
+ * creates a new swap file with extension `.1.crswap` and so on.
14
+ */
15
+ const createSwapFile = async (fs, path, keepExistingData) => {
16
+ let handle;
17
+ let swapPath = path + '.crswap';
18
+ try {
19
+ handle = await fs.promises.open(swapPath, 'ax');
20
+ }
21
+ catch (error) {
22
+ if (!error || typeof error !== 'object' || error.code !== 'EEXIST')
23
+ throw error;
24
+ }
25
+ if (!handle) {
26
+ for (let i = 1; i < 1000; i++) {
27
+ try {
28
+ swapPath = `${path}.${i}.crswap`;
29
+ handle = await fs.promises.open(swapPath, 'ax');
30
+ break;
31
+ }
32
+ catch (error) {
33
+ if (!error || typeof error !== 'object' || error.code !== 'EEXIST')
34
+ throw error;
35
+ }
36
+ }
37
+ }
38
+ if (!handle)
39
+ throw new Error(`Could not create a swap file for "${path}".`);
40
+ if (keepExistingData)
41
+ await fs.promises.copyFile(path, swapPath, fs.constants.COPYFILE_FICLONE);
42
+ return [handle, swapPath];
43
+ };
44
+ exports.createSwapFile = createSwapFile;
45
+ const WS = (typeof WritableStream === 'undefined' ? require('stream/web').WritableStream : WritableStream);
46
+ /**
47
+ * Is a WritableStream object with additional convenience methods, which
48
+ * operates on a single file on disk. The interface is accessed through the
49
+ * `FileSystemFileHandle.createWritable()` method.
50
+ *
51
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemWritableFileStream
52
+ */
53
+ class NodeFileSystemWritableFileStream extends WS {
54
+ constructor(fs, path, keepExistingData, ctx) {
55
+ const swap = { handle: undefined, path: '', offset: 0 };
56
+ super({
57
+ async start() {
58
+ if (ctx.locks.isLocked(path)) {
59
+ throw (0, util_1.newNoModificationAllowedError)();
60
+ }
61
+ ctx.locks.acquireLock(path);
62
+ try {
63
+ const promise = (0, exports.createSwapFile)(fs, path, keepExistingData);
64
+ swap.ready = promise.then(() => undefined);
65
+ const [handle, swapPath] = await promise;
66
+ swap.handle = handle;
67
+ swap.path = swapPath;
68
+ }
69
+ catch (error) {
70
+ ctx.locks.releaseLock(path);
71
+ throw error;
72
+ }
73
+ },
74
+ async write(chunk) {
75
+ await swap.ready;
76
+ const handle = swap.handle;
77
+ if (!handle)
78
+ throw new Error('Invalid state');
79
+ const buffer = buffer_1.Buffer.from(typeof chunk === 'string'
80
+ ? chunk
81
+ : chunk instanceof Blob
82
+ ? new Uint8Array(await chunk.arrayBuffer())
83
+ : chunk);
84
+ const { bytesWritten } = await handle.write(buffer, 0, buffer.length, swap.offset);
85
+ swap.offset += bytesWritten;
86
+ },
87
+ async close() {
88
+ await swap.ready;
89
+ const handle = swap.handle;
90
+ if (!handle)
91
+ return;
92
+ await handle.close();
93
+ await fs.promises.rename(swap.path, path);
94
+ ctx.locks.releaseLock(path);
95
+ },
96
+ async abort() {
97
+ await swap.ready;
98
+ const handle = swap.handle;
99
+ if (!handle)
100
+ return;
101
+ await handle.close();
102
+ await fs.promises.unlink(swap.path);
103
+ ctx.locks.releaseLock(path);
104
+ },
105
+ });
106
+ this.fs = fs;
107
+ this.path = path;
108
+ this.ctx = ctx;
109
+ this.swap = swap;
110
+ }
111
+ /**
112
+ * @sse https://developer.mozilla.org/en-US/docs/Web/API/FileSystemWritableFileStream/seek
113
+ * @param position An `unsigned long` describing the byte position from the top
114
+ * (beginning) of the file.
115
+ */
116
+ async seek(position) {
117
+ this.swap.offset = position;
118
+ }
119
+ /**
120
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemWritableFileStream/truncate
121
+ * @param size An `unsigned long` of the amount of bytes to resize the stream to.
122
+ */
123
+ async truncate(size) {
124
+ await this.swap.ready;
125
+ const handle = this.swap.handle;
126
+ if (!handle)
127
+ throw new Error('Invalid state');
128
+ await handle.truncate(size);
129
+ if (this.swap.offset > size)
130
+ this.swap.offset = size;
131
+ }
132
+ async writeBase(chunk) {
133
+ const writer = this.getWriter();
134
+ try {
135
+ await writer.write(chunk);
136
+ }
137
+ finally {
138
+ writer.releaseLock();
139
+ }
140
+ }
141
+ async write(params) {
142
+ if (!params)
143
+ throw new TypeError('Missing required argument: params');
144
+ switch (typeof params) {
145
+ case 'string': {
146
+ return this.writeBase(params);
147
+ }
148
+ case 'object': {
149
+ const constructor = params.constructor;
150
+ switch (constructor) {
151
+ case ArrayBuffer:
152
+ case Blob:
153
+ case DataView:
154
+ return this.writeBase(params);
155
+ default: {
156
+ if (ArrayBuffer.isView(params)) {
157
+ return this.writeBase(params);
158
+ }
159
+ else {
160
+ const options = params;
161
+ switch (options.type) {
162
+ case 'write': {
163
+ if (typeof options.position === 'number')
164
+ await this.seek(options.position);
165
+ return this.writeBase(params.data);
166
+ }
167
+ case 'truncate': {
168
+ if (typeof params.size !== 'number')
169
+ throw new TypeError('Missing required argument: size');
170
+ if (this.swap.offset > params.size)
171
+ this.swap.offset = params.size;
172
+ return this.truncate(params.size);
173
+ }
174
+ case 'seek':
175
+ if (typeof params.position !== 'number')
176
+ throw new TypeError('Missing required argument: position');
177
+ return this.seek(params.position);
178
+ default:
179
+ throw new TypeError('Invalid argument: params');
180
+ }
181
+ }
182
+ }
183
+ }
184
+ }
185
+ default:
186
+ throw new TypeError('Invalid argument: params');
187
+ }
188
+ }
189
+ }
190
+ exports.NodeFileSystemWritableFileStream = NodeFileSystemWritableFileStream;
191
+ //# sourceMappingURL=NodeFileSystemWritableFileStream.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NodeFileSystemWritableFileStream.js","sourceRoot":"","sources":["../src/NodeFileSystemWritableFileStream.ts"],"names":[],"mappings":";;;AAAA,8EAA2E;AAI3E,iCAAuD;AAEvD;;;;;;;;GAQG;AACI,MAAM,cAAc,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CAAC,CAAC;gCACpC;oCACE,MAAM,IAAI,SAAS,CAAC,0BAA0B,CAAC,CAAC;4BACpD,CAAC;wBACH,CAAC;oBACH,CAAC;gBACH,CAAC;YACH,CAAC;YACD;gBACE,MAAM,IAAI,SAAS,CAAC,0BAA0B,CAAC,CAAC;QACpD,CAAC;IACH,CAAC;CACF;AA1ID,4EA0IC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @see [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/PermissionStatus)
3
+ */
4
+ export declare class NodePermissionStatus {
5
+ readonly name: string;
6
+ readonly state: 'granted' | 'denied' | 'prompt';
7
+ constructor(name: string, state: 'granted' | 'denied' | 'prompt');
8
+ }
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NodePermissionStatus = void 0;
4
+ /**
5
+ * @see [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/PermissionStatus)
6
+ */
7
+ class NodePermissionStatus {
8
+ constructor(name, state) {
9
+ this.name = name;
10
+ this.state = state;
11
+ }
12
+ }
13
+ exports.NodePermissionStatus = NodePermissionStatus;
14
+ //# sourceMappingURL=NodePermissionStatus.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NodePermissionStatus.js","sourceRoot":"","sources":["../src/NodePermissionStatus.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,MAAa,oBAAoB;IAC/B,YACkB,IAAY,EACZ,KAAsC;QADtC,SAAI,GAAJ,IAAI,CAAQ;QACZ,UAAK,GAAL,KAAK,CAAiC;IACrD,CAAC;CACL;AALD,oDAKC"}
package/lib/index.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ import { NodeFileSystemDirectoryHandle } from './NodeFileSystemDirectoryHandle';
2
+ import { NodeFsaContext, NodeFsaFs } from './types';
3
+ export * from './types';
4
+ export * from './NodeFileSystemHandle';
5
+ export * from './NodeFileSystemDirectoryHandle';
6
+ export * from './NodeFileSystemFileHandle';
7
+ export declare const nodeToFsa: (fs: NodeFsaFs, dirPath: string, ctx?: Partial<NodeFsaContext>) => NodeFileSystemDirectoryHandle;
package/lib/index.js ADDED
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.nodeToFsa = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const NodeFileSystemDirectoryHandle_1 = require("./NodeFileSystemDirectoryHandle");
6
+ tslib_1.__exportStar(require("./types"), exports);
7
+ tslib_1.__exportStar(require("./NodeFileSystemHandle"), exports);
8
+ tslib_1.__exportStar(require("./NodeFileSystemDirectoryHandle"), exports);
9
+ tslib_1.__exportStar(require("./NodeFileSystemFileHandle"), exports);
10
+ const nodeToFsa = (fs, dirPath, ctx) => {
11
+ return new NodeFileSystemDirectoryHandle_1.NodeFileSystemDirectoryHandle(fs, dirPath, ctx);
12
+ };
13
+ exports.nodeToFsa = nodeToFsa;
14
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;AAAA,mFAAgF;AAGhF,kDAAwB;AACxB,iEAAuC;AACvC,0EAAgD;AAChD,qEAA2C;AAEpC,MAAM,SAAS,GAAG,CACvB,EAAa,EACb,OAAe,EACf,GAA6B,EACE,EAAE;IACjC,OAAO,IAAI,6DAA6B,CAAC,EAAE,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC;AAC7D,CAAC,CAAC;AANW,QAAA,SAAS,aAMpB"}
package/lib/types.d.ts ADDED
@@ -0,0 +1,18 @@
1
+ import type { FsPromisesApi, FsSynchronousApi } from '@jsonjoy.com/fs-node-utils';
2
+ import type { FsCommonObjects } from '@jsonjoy.com/fs-node-utils/lib/types/FsCommonObjects';
3
+ import type { FileLockManager } from '@jsonjoy.com/fs-fsa';
4
+ /**
5
+ * Required Node.js `fs` module functions for File System Access API.
6
+ */
7
+ export type NodeFsaFs = Pick<FsCommonObjects, 'constants'> & {
8
+ promises: FsPromisesApi;
9
+ } & Pick<FsSynchronousApi, 'openSync' | 'fsyncSync' | 'statSync' | 'closeSync' | 'readSync' | 'truncateSync' | 'writeSync' | 'accessSync'>;
10
+ export interface NodeFsaContext {
11
+ separator: '/' | '\\';
12
+ /** Whether synchronous file handles are allowed. */
13
+ syncHandleAllowed: boolean;
14
+ /** Whether writes are allowed, defaults to `read`. */
15
+ mode: 'read' | 'readwrite';
16
+ /** File lock manager for this context. */
17
+ locks: FileLockManager;
18
+ }
package/lib/types.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/lib/util.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ import type { NodeFsaContext } from './types';
2
+ export { basename } from '@jsonjoy.com/fs-node-utils';
3
+ /**
4
+ * Creates a new {@link NodeFsaContext}.
5
+ */
6
+ export declare const ctx: (partial?: Partial<NodeFsaContext>) => NodeFsaContext;
7
+ export declare const assertName: (name: string, method: string, klass: string) => void;
8
+ export declare const assertCanWrite: (mode: "read" | "readwrite") => void;
9
+ export declare const newNotFoundError: () => DOMException;
10
+ export declare const newTypeMismatchError: () => DOMException;
11
+ export declare const newNotAllowedError: () => DOMException;
12
+ export declare const newNoModificationAllowedError: () => DOMException;