@@ -18,10 +18,9 @@ import { InstantiationProgress } from '../bindings/progress';
1818import { arrowToSQLField } from '../json_typedef' ;
1919import { WebFile } from '../bindings/web_file' ;
2020import { DuckDBDataProtocol } from '../bindings' ;
21+ import { searchOPFSFiles , isOPFSProtocol } from "../utils/opfs_util" ;
2122
2223const TEXT_ENCODER = new TextEncoder ( ) ;
23- const REGEX_OPFS_FILE = / ' ( o p f s : \/ \/ \S * ?) ' / g;
24- const REGEX_OPFS_PROTOCOL = / ( o p f s : \/ \/ \S * ?) / g;
2524
2625export class AsyncDuckDB implements AsyncDuckDBBindings {
2726 /** The message handler */
@@ -404,8 +403,8 @@ export class AsyncDuckDB implements AsyncDuckDBBindings {
404403
405404 /** Run a query */
406405 public async runQuery ( conn : ConnectionID , text : string ) : Promise < Uint8Array > {
407- if ( this . isOpenedOPFSAutoFileRegistration ( ) ) {
408- const files = await this . _preFileRegistration ( text ) ;
406+ if ( this . shouldOPFSFileHandling ( ) ) {
407+ const files = await this . registerOPFSFileFromSQL ( text ) ;
409408 try {
410409 return await this . _runQueryAsync ( conn , text ) ;
411410 } finally {
@@ -432,8 +431,8 @@ export class AsyncDuckDB implements AsyncDuckDBBindings {
432431 text : string ,
433432 allowStreamResult : boolean = false ,
434433 ) : Promise < Uint8Array | null > {
435- if ( this . isOpenedOPFSAutoFileRegistration ( ) ) {
436- const files = await this . _preFileRegistration ( text ) ;
434+ if ( this . shouldOPFSFileHandling ( ) ) {
435+ const files = await this . registerOPFSFileFromSQL ( text ) ;
437436 try {
438437 return await this . _startPendingQueryAsync ( conn , text , allowStreamResult ) ;
439438 } finally {
@@ -693,16 +692,15 @@ export class AsyncDuckDB implements AsyncDuckDBBindings {
693692 await this . postTask ( task ) ;
694693 }
695694
696- private isOpenedOPFSAutoFileRegistration ( ) :boolean {
697- let path = this . config . path ?? "" ;
698- if ( path . search ( REGEX_OPFS_PROTOCOL ) > - 1 ) {
699- return this . config . opfs ?. autoFileRegistration ?? false ;
695+ private shouldOPFSFileHandling ( ) :boolean {
696+ if ( isOPFSProtocol ( this . config . path ?? "" ) ) {
697+ return this . config . opfs ?. fileHandling == "auto" ;
700698 }
701699 return false ;
702700 }
703701
704- private async _preFileRegistration ( text : string ) {
705- const files = [ ... text . matchAll ( REGEX_OPFS_FILE ) ] . map ( match => match [ 1 ] ) ;
702+ private async registerOPFSFileFromSQL ( text : string ) {
703+ const files = searchOPFSFiles ( text ) ;
706704 const result : string [ ] = [ ] ;
707705 for ( const file of files ) {
708706 try {
0 commit comments