Skip to content

Commit

Permalink
Move back to syncronous function registerFileHandle in DuckDBBindings
Browse files Browse the repository at this point in the history
Iterating on duckdb#1856
  • Loading branch information
carlopi committed Jan 15, 2025
1 parent c1365cf commit 7456b46
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
27 changes: 23 additions & 4 deletions packages/duckdb-wasm/src/bindings/bindings_base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -476,20 +476,20 @@ export abstract class DuckDBBindingsBase implements DuckDBBindings {
for (const item of list) {
const { handle, path: filePath, fromCached } = item;
if (!fromCached && handle.getSize()) {
await this.registerFileHandle(filePath, handle, DuckDBDataProtocol.BROWSER_FSACCESS, true);
await this.registerFileHandleAsync(filePath, handle, DuckDBDataProtocol.BROWSER_FSACCESS, true);
}
}
return;
}
throw new Error(`prepareDBFileHandle: unsupported protocol ${protocol}`);
}
/** Register a file object URL */
public async registerFileHandle<HandleType>(
/** Prepare a file object URL */
public async prepareFileHandleAsync<HandleType>(
name: string,
handle: HandleType,
protocol: DuckDBDataProtocol,
directIO: boolean,
): Promise<void> {
): Promise<HandleType> {
if (protocol === DuckDBDataProtocol.BROWSER_FSACCESS) {
if( handle instanceof FileSystemSyncAccessHandle ){
// already a handle is sync handle.
Expand All @@ -512,6 +512,25 @@ export abstract class DuckDBBindingsBase implements DuckDBBindings {
}
}
}
return handle;
}
/** Register a file object URL async */
public async registerFileHandleAsync<HandleType>(
name: string,
handle: HandleType,
protocol: DuckDBDataProtocol,
directIO: boolean,
): Promise<void> {
const handle_inner = await this.prepareFileHandleAsync(name, handle, protocol, directIO);
this.registerFileHandle(name, handle_inner, protocol, directIO);
}
/** Register a file object URL */
public registerFileHandle<HandleType>(
name: string,
handle: HandleType,
protocol: DuckDBDataProtocol,
directIO: boolean,
): void {
const [s, d, n] = callSRet(
this.mod,
'duckdb_web_fs_register_file_url',
Expand Down
12 changes: 12 additions & 0 deletions packages/duckdb-wasm/src/bindings/bindings_interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,19 @@ export interface DuckDBBindings {
handle: HandleType,
protocol: DuckDBDataProtocol,
directIO: boolean,
): void;
registerFileHandleAsync<HandleType>(
name: string,
handle: HandleType,
protocol: DuckDBDataProtocol,
directIO: boolean,
): Promise<void>;
prepareFileHandleAsync<HandleType>(
name: string,
handle: HandleType,
protocol: DuckDBDataProtocol,
directIO: boolean,
): Promise<HandleType>;
prepareDBFileHandle(path: string, protocol: DuckDBDataProtocol): Promise<void>;
globFiles(path: string): WebFile[];
dropFile(name: string): void;
Expand Down
2 changes: 1 addition & 1 deletion packages/duckdb-wasm/src/parallel/worker_dispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ export abstract class AsyncDuckDBDispatcher implements Logger {
break;

case WorkerRequestType.REGISTER_FILE_HANDLE:
await this._bindings.registerFileHandle(
await this._bindings.registerFileHandleAsync(
request.data[0],
request.data[1],
request.data[2],
Expand Down

0 comments on commit 7456b46

Please sign in to comment.