Skip to content

Commit

Permalink
fix(api/fs/web.js): make 'getFile' async
Browse files Browse the repository at this point in the history
  • Loading branch information
jwerle committed Aug 20, 2024
1 parent 493fafc commit c9c6d91
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions api/fs/web.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const FileSystemHandle = globalThis.FileSystemHandle ??
// @ts-ignore
export const FileSystemFileHandle = globalThis.FileSystemFileHandle ??
class FileSystemFileHandle extends FileSystemHandle {
getFile () {}
async getFile () {}
async createWritable (options = null) {}
async createSyncAccessHandle () {}
}
Expand Down Expand Up @@ -280,7 +280,7 @@ export async function createFileSystemWritableFileStream (handle, options) {
console.warn('socket:fs/web: Missing platform \'FileSystemWritableFileStream\' implementation')
}

const file = handle.getFile()
const file = await handle.getFile()
let offset = 0
let fd = null

Expand Down Expand Up @@ -375,10 +375,6 @@ export async function createFileSystemFileHandle (file, options = null) {
console.warn('socket:fs/web: Missing platform \'FileSystemFileHandle\' implementation')
}

if (typeof file === 'string') {
file = await createFile(file)
}

return create(FileSystemFileHandle, class FileSystemFileHandle {
get [kFileSystemHandleFullName] () { return file[kFileFullName] }
get [kFileDescriptor] () { return file[kFileDescriptor] }
Expand All @@ -391,7 +387,11 @@ export async function createFileSystemFileHandle (file, options = null) {
return 'file'
}

getFile () {
async getFile () {
if (typeof file === 'string') {
file = await createFile(file)
}

return file
}

Expand All @@ -417,10 +417,14 @@ export async function createFileSystemFileHandle (file, options = null) {
}

async move (nameOrDestinationHandle, name = null) {
if (writable === false || URL.canParse(file?.name)) {
if (writable === false || URL.canParse(file?.name ?? file)) {
throw new NotAllowedError('FileSystemFileHandle is in \'readonly\' mode')
}

if (typeof file === 'string') {
file = await createFile(file)
}

let destination = null
if (typeof nameOrDestinationHandle === 'string') {
name = nameOrDestinationHandle
Expand All @@ -443,10 +447,14 @@ export async function createFileSystemFileHandle (file, options = null) {
}

async createWritable (options = null) {
if (writable === false || URL.canParse(file?.name)) {
if (writable === false || URL.canParse(file?.name ?? file)) {
throw new NotAllowedError('FileSystemFileHandle is in \'readonly\' mode')
}

if (typeof file === 'string') {
file = await createFile(file)
}

return await createFileSystemWritableFileStream(this, options)
}
})
Expand Down

0 comments on commit c9c6d91

Please sign in to comment.