Skip to content

Commit

Permalink
feat: 🎸 setup node-to-fsa folder
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich committed Jun 20, 2023
1 parent e9fba95 commit a4268c6
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 1 deletion.
30 changes: 30 additions & 0 deletions src/node-to-fsa/NodeFileSystemFileHandle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import {IFileHandle} from "../promises";
import {NodeFileSystemHandle} from "./NodeFileSystemHandle";
import {NodeFileSystemSyncAccessHandle} from "./NodeFileSystemSyncAccessHandle";

export class NodeFileSystemFileHandle extends NodeFileSystemHandle {
constructor (name: string, protected readonly handle: IFileHandle) {
super('file', name);
}

/**
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemFileHandle/getFile
*/
public async getFile(): Promise<File> {
throw new Error('Not implemented');
}

/**
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemFileHandle/createSyncAccessHandle
*/
public async createSyncAccessHandle(): Promise<NodeFileSystemSyncAccessHandle> {
throw new Error('Not implemented');
}

/**
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemFileHandle/createWritable
*/
public async createWritable({keepExistingData = false}: {keepExistingData?: boolean} = {keepExistingData: false}): Promise<NodeFileSystemSyncAccessHandle> {
throw new Error('Not implemented');
}
}
43 changes: 43 additions & 0 deletions src/node-to-fsa/NodeFileSystemHandle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import {NodePermissionStatus} from "./NodePermissionStatus";
import type {NodeFileSystemHandlePermissionDescriptor} from "./types";

/**
* Represents a File System Access API file handle `FileSystemHandle` object,
* which was created from a Node.js `fs` module.
*
* @see [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/FileSystemHandle)
*/
export abstract class NodeFileSystemHandle {
constructor (
public readonly kind: 'file' | 'directory',
public readonly name: string,
) {}

/**
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemHandle/isSameEntry
*/
public isSameEntry(fileSystemHandle: NodeFileSystemHandle): boolean {
throw new Error('Not implemented');
}

/**
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemHandle/queryPermission
*/
public queryPermission(fileSystemHandlePermissionDescriptor: NodeFileSystemHandlePermissionDescriptor): NodePermissionStatus {
throw new Error('Not implemented');
}

/**
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemHandle/remove
*/
public async remove({recursive}: {recursive?: boolean} = {recursive: false}): Promise<void> {
throw new Error('Not implemented');
}

/**
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemHandle/requestPermission
*/
public requestPermission(fileSystemHandlePermissionDescriptor: NodeFileSystemHandlePermissionDescriptor): NodePermissionStatus {
throw new Error('Not implemented');
}
}
1 change: 1 addition & 0 deletions src/node-to-fsa/NodeFileSystemSyncAccessHandle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export class NodeFileSystemSyncAccessHandle {}
6 changes: 6 additions & 0 deletions src/node-to-fsa/NodeFileSystemWritableFileStream.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemWritableFileStream
*/
export class NodeFileSystemWritableFileStream extends WritableStream {

}
9 changes: 9 additions & 0 deletions src/node-to-fsa/NodePermissionStatus.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* @see [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/PermissionStatus)
*/
export class NodePermissionStatus {
constructor (
public readonly name: string,
public readonly state: 'granted' | 'denied' | 'prompt',
) {}
}
1 change: 1 addition & 0 deletions src/node-to-fsa/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This adapter code converts an instance of [Node.js FS API](https://nodejs.org/api/fs.html) to a [File System Access API](https://developer.mozilla.org/en-US/docs/Web/API/File_System_Access_API) (FSA) instance.
3 changes: 3 additions & 0 deletions src/node-to-fsa/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface NodeFileSystemHandlePermissionDescriptor {
mode: 'read' | 'readwrite';
}
2 changes: 1 addition & 1 deletion src/promises.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
import Stats from './Stats';
import Dirent from './Dirent';
import { TDataOut } from './encoding';
import { PathLike, symlink } from 'fs';
import type { PathLike, symlink } from 'fs';

function promisify(
vol: Volume,
Expand Down

0 comments on commit a4268c6

Please sign in to comment.