Skip to content

Commit

Permalink
feat: 🎸 standartize message contents
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich committed Jun 19, 2023
1 parent 0647395 commit c254dc7
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 26 deletions.
12 changes: 6 additions & 6 deletions src/fsa-to-node/FsaNodeFs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ export class FsaNodeFs extends FsaNodeCore implements FsCallbackApi, FsSynchrono
const filename = pathToFilename(path);
mode = mode | 0;
const adapter = this.getSyncAdapter();
adapter.call('access', { filename, mode });
adapter.call('access', [filename, mode]);
};

public readonly readFileSync: FsSynchronousApi['readFileSync'] = (
Expand All @@ -830,7 +830,7 @@ export class FsaNodeFs extends FsaNodeCore implements FsCallbackApi, FsSynchrono
const flagsNum = flagsToNumber(opts.flag);
const filename = this.getFileName(id);
const adapter = this.getSyncAdapter();
const uint8 = adapter.call('readFile', { filename, opts });
const uint8 = adapter.call('readFile', [filename, opts]);
const buffer = Buffer.from(uint8.buffer, uint8.byteOffset, uint8.byteLength);
return bufferToEncoding(buffer, opts.encoding);
};
Expand All @@ -846,7 +846,7 @@ export class FsaNodeFs extends FsaNodeCore implements FsCallbackApi, FsSynchrono
const buf = dataToBuffer(data, opts.encoding);
const filename = this.getFileName(id);
const adapter = this.getSyncAdapter();
adapter.call('writeFile', { filename, data: bufToUint8(buf), opts });
adapter.call('writeFile', [filename, bufToUint8(buf), opts]);
};

public readonly appendFileSync: FsSynchronousApi['appendFileSync'] = (
Expand All @@ -859,7 +859,7 @@ export class FsaNodeFs extends FsaNodeCore implements FsCallbackApi, FsSynchrono
const filename = this.getFileName(id);
const buf = dataToBuffer(data, opts.encoding);
const adapter = this.getSyncAdapter();
adapter.call('appendFile', { filename, data: bufToUint8(buf), opts });
adapter.call('appendFile', [filename, bufToUint8(buf), opts]);
};

public readonly closeSync: FsSynchronousApi['closeSync'] = (fd: number) => {
Expand Down Expand Up @@ -887,7 +887,7 @@ export class FsaNodeFs extends FsaNodeCore implements FsCallbackApi, FsSynchrono
const srcFilename = pathToFilename(src);
const destFilename = pathToFilename(dest);
const adapter = this.getSyncAdapter();
adapter.call('copy', { src: srcFilename, dst: destFilename, flags });
adapter.call('copy', [srcFilename, destFilename, flags]);
};

public readonly renameSync: FsSynchronousApi['renameSync'] = (
Expand All @@ -897,7 +897,7 @@ export class FsaNodeFs extends FsaNodeCore implements FsCallbackApi, FsSynchrono
const srcFilename = pathToFilename(oldPath);
const destFilename = pathToFilename(newPath);
const adapter = this.getSyncAdapter();
adapter.call('move', { src: srcFilename, dst: destFilename });
adapter.call('move', [srcFilename, destFilename]);
};

public readonly rmdirSync: FsSynchronousApi['rmdirSync'] = (path: misc.PathLike, opts?: opts.IRmdirOptions): void => {
Expand Down
10 changes: 2 additions & 8 deletions src/fsa-to-node/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
import { FsaNodeFs } from './FsaNodeFs';
import { FsaNodeSyncAdapterWorker } from './worker/FsaNodeSyncAdapterWorker';
import type { IFileSystemDirectoryHandle } from '../fsa/types';
export { FsaNodeFs } from './FsaNodeFs';
export { FsaNodeSyncAdapterWorker } from './worker/FsaNodeSyncAdapterWorker';

export { FsaNodeFs, FsaNodeSyncAdapterWorker };

export const fsaToNode = (root: IFileSystemDirectoryHandle) => {
return new FsaNodeFs(root);
};
12 changes: 6 additions & 6 deletions src/fsa-to-node/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ export type FsLocation = [folder: string[], file: string];
*/
export interface FsaNodeSyncAdapterApi {
stat(location: FsLocation): FsaNodeSyncAdapterStats;
access(req: { filename: string; mode: number }): void;
readFile(req: { filename: string; opts?: opts.IReadFileOptions }): Uint8Array;
writeFile(req: { filename: string; data: Uint8Array; opts?: opts.IWriteFileOptions }): void;
appendFile(req: { filename: string; data: Uint8Array; opts?: opts.IAppendFileOptions }): void;
copy(req: { src: string; dst: string; flags?: number }): void;
move(req: { src: string; dst: string }): void;
access(req: [filename: string, mode: number]): void;
readFile(req: [filename: string, opts?: opts.IReadFileOptions]): Uint8Array;
writeFile(req: [filename: string, data: Uint8Array, opts?: opts.IWriteFileOptions]): void;
appendFile(req: [filename: string, data: Uint8Array, opts?: opts.IAppendFileOptions]): void;
copy(req: [src: string, dst: string, flags?: number]): void;
move(req: [src: string, dst: string]): void;
rmdir(req: [filename: string, opts?: opts.IRmdirOptions]): void;
rm(req: [filename: string, opts?: opts.IRmOptions]): void;
mkdir(req: [filename: string, opts?: misc.TMode | opts.IMkdirOptions]): string | undefined;
Expand Down
12 changes: 6 additions & 6 deletions src/fsa-to-node/worker/FsaNodeSyncWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,24 +122,24 @@ export class FsaNodeSyncWorker {
kind: handle.kind,
};
},
access: async ({ filename, mode }): Promise<void> => {
access: async ([filename, mode]): Promise<void> => {
await this.fs.promises.access(filename, mode);
},
readFile: async ({ filename, opts }): Promise<Uint8Array> => {
readFile: async ([filename, opts]): Promise<Uint8Array> => {
const buf = (await this.fs.promises.readFile(filename, { ...opts, encoding: 'buffer' })) as Buffer;
const uint8 = new Uint8Array(buf, buf.byteOffset, buf.byteLength);
return uint8;
},
writeFile: async ({ filename, data, opts }): Promise<void> => {
writeFile: async ([filename, data, opts]): Promise<void> => {
await this.fs.promises.writeFile(filename, data, { ...opts, encoding: 'buffer' });
},
appendFile: async ({ filename, data, opts }): Promise<void> => {
appendFile: async ([filename, data, opts]): Promise<void> => {
await this.fs.promises.appendFile(filename, data, { ...opts, encoding: 'buffer' });
},
copy: async ({ src, dst, flags }): Promise<void> => {
copy: async ([src, dst, flags]): Promise<void> => {
await this.fs.promises.copyFile(src, dst, flags);
},
move: async ({ src, dst }): Promise<void> => {
move: async ([src, dst]): Promise<void> => {
await this.fs.promises.rename(src, dst);
},
rmdir: async ([filename, options]): Promise<void> => {
Expand Down

0 comments on commit c254dc7

Please sign in to comment.