You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Im trying to create a transferHandle for Origin Private File System (OPFS) file handles since they are not cloneable in all browsers. This is the approach I tried:
/** * Check if the given value is a FileHandle and if it needs to be serialized. * @param value * @returns */functioncanHandle(value: unknown): value is FileSystemFileHandle{constisFileHandle=valueinstanceofFileSystemFileHandleif(!isFileHandle){returnfalse;}try{// if we can clone the value, there is no need to serialize itstructuredClone(value);returnfalse;}catch{// if we can't clone the value, we need to serialize it}returntrue;}transferHandlers.set('FileHandle',{
canHandle,serialize: async(ev)=>{constroot=awaitnavigator.storage.getDirectory();return[awaitroot.resolve(ev),[]];},deserialize: async(path)=>{letdirectory=awaitnavigator.storage.getDirectory();constfileName=path.pop();for(constpartofpath){directory=awaitdirectory.getDirectoryHandle(part,{create: true});}returndirectory.getDirectoryHandle(fileName,{create: true});}}satisfiesTransferHandler<FileSystemFileHandle,string[]>);
However, I've run into an issue where the serializer and deserializer functions are not compatible with Promises. This is causing the transferHandle to not work as expected.
I'm wondering if there is another way to solve this issue or if I need to do the serialization manually. Any help or suggestions would be greatly appreciated.
The text was updated successfully, but these errors were encountered:
Im trying to create a transferHandle for Origin Private File System (OPFS) file handles since they are not cloneable in all browsers. This is the approach I tried:
However, I've run into an issue where the serializer and deserializer functions are not compatible with Promises. This is causing the transferHandle to not work as expected.
I'm wondering if there is another way to solve this issue or if I need to do the serialization manually. Any help or suggestions would be greatly appreciated.
The text was updated successfully, but these errors were encountered: