Skip to content

Commit

Permalink
Updated support for mount and other filesystems.
Browse files Browse the repository at this point in the history
  • Loading branch information
LostBeard committed Sep 13, 2023
1 parent 71ac16f commit 1abd8d3
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 17 deletions.
21 changes: 12 additions & 9 deletions packages/ffmpeg/src/classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import {
ProgressEventCallback,
FileData,
WorkerFSMountData,
FFFSType,
FFFSMountOptions,
FFFSPath,
} from "./types.js";
import { getMessageID } from "./utils.js";
import { ERROR_TERMINATED, ERROR_NOT_LOADED } from "./errors.js";
Expand Down Expand Up @@ -263,23 +266,23 @@ export class FFmpeg {
) as Promise<OK>;
};

public mount = (path: string, data: WorkerFSMountData): Promise<OK> => {
public mount = (fsType: FFFSType, options: FFFSMountOptions, mountPoint: FFFSPath, ): Promise<OK> => {
const trans: Transferable[] = [];
return this.#send(
{
type: FFMessageType.MOUNT,
data: { path, data },
data: { fsType, options, mountPoint },
},
trans
) as Promise<OK>;
};

public unmount = (path: string): Promise<OK> => {
public unmount = (mountPoint: FFFSPath): Promise<OK> => {
const trans: Transferable[] = [];
return this.#send(
{
type: FFMessageType.UNMOUNT,
data: { path },
data: { mountPoint },
},
trans
) as Promise<OK>;
Expand Down Expand Up @@ -310,7 +313,7 @@ export class FFmpeg {
): Promise<FileData> =>
this.#send({
type: FFMessageType.READ_FILE,
data: { path, encoding },
data: { mountPoint: path, encoding },
}) as Promise<FileData>;

/**
Expand All @@ -321,7 +324,7 @@ export class FFmpeg {
public deleteFile = (path: string): Promise<OK> =>
this.#send({
type: FFMessageType.DELETE_FILE,
data: { path },
data: { mountPoint: path },
}) as Promise<OK>;

/**
Expand All @@ -343,7 +346,7 @@ export class FFmpeg {
public createDir = (path: string): Promise<OK> =>
this.#send({
type: FFMessageType.CREATE_DIR,
data: { path },
data: { mountPoint: path },
}) as Promise<OK>;

/**
Expand All @@ -354,7 +357,7 @@ export class FFmpeg {
public listDir = (path: string): Promise<FSNode[]> =>
this.#send({
type: FFMessageType.LIST_DIR,
data: { path },
data: { mountPoint: path },
}) as Promise<FSNode[]>;

/**
Expand All @@ -365,6 +368,6 @@ export class FFmpeg {
public deleteDir = (path: string): Promise<OK> =>
this.#send({
type: FFMessageType.DELETE_DIR,
data: { path },
data: { mountPoint: path },
}) as Promise<OK>;
}
2 changes: 1 addition & 1 deletion packages/ffmpeg/src/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ export enum FFMessageType {
MOUNT = "MOUNT",
UNMOUNT = "UNMOUNT",
FILESYSTEMS = "FILESYSTEMS",
}
}
19 changes: 16 additions & 3 deletions packages/ffmpeg/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ export interface FFMessageDeleteDirData {
path: FFFSPath;
}

export enum FFFSType {
MEMFS = "MEMFS",
NODEFS = "NODEFS",
NODERAWFS = "NODERAWFS",
IDBFS = "IDBFS",
WORKERFS = "WORKERFS",
PROXYFS = "PROXYFS",
}

export type WorkerFSFileEntry =
| File;

Expand All @@ -83,13 +92,17 @@ export interface WorkerFSMountData {
files?: WorkerFSFileEntry[];
}

export type FFFSMountOptions =
| WorkerFSMountData;

export interface FFMessageMountData {
path: FFFSPath;
data: WorkerFSMountData;
fsType: FFFSType;
options: FFFSMountOptions;
mountPoint: FFFSPath;
}

export interface FFMessageUnmountData {
path: FFFSPath;
mountPoint: FFFSPath;
}

export type FFMessageData =
Expand Down
11 changes: 7 additions & 4 deletions packages/ffmpeg/src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,16 @@ const deleteDir = ({ path }: FFMessageDeleteDirData): OK => {
return true;
};

const mount = ({ path, data }: FFMessageMountData): OK => {
ffmpeg.FS.mount(ffmpeg.FS.filesystems.WORKERFS, data, path);
const mount = ({ fsType, options, mountPoint }: FFMessageMountData): OK => {
let str = fsType as keyof typeof ffmpeg.FS.filesystems;
let fs = ffmpeg.FS.filesystems[str];
if (!fs) return false;
ffmpeg.FS.mount(fs, options, mountPoint);
return true;
};

const unmount = ({ path }: FFMessageUnmountData): OK => {
ffmpeg.FS.unmount(path);
const unmount = ({ mountPoint }: FFMessageUnmountData): OK => {
ffmpeg.FS.unmount(mountPoint);
return true;
};

Expand Down

0 comments on commit 1abd8d3

Please sign in to comment.