Skip to content

Commit

Permalink
fix(FileSystemAccessApiFsClient): attempt to fix writeFile for safari
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-titarenko committed Jan 9, 2023
1 parent 74ddb20 commit e97f513
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/clients/fs/FileSystemAccessApiFsClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,9 @@ const textEncoder = new TextEncoder();
async function writeFile(fileHandle: FileSystemFileHandle, data: ArrayBuffer | string, useSyncAccessHandle: boolean) {
if (useSyncAccessHandle) {
const accessHandle = await fileHandle.createSyncAccessHandle()
accessHandle.write(typeof data === 'string' ? textEncoder.encode(data) : data, { at: 0 })
const content = typeof data === 'string' ? textEncoder.encode(data) : data;
accessHandle.write(content, { at: 0 })
await accessHandle.truncate(content.byteLength);
await accessHandle.flush()
await accessHandle.close()
} else {
Expand Down
1 change: 1 addition & 0 deletions src/types/FileSystemAccessApi.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ declare interface FileSystemReadWriteOptions {
declare interface FileSystemSyncAccessHandle {
read(buffer: ArrayBuffer, options?: FileSystemReadWriteOptions): number
write(buffer: ArrayBuffer, options?: FileSystemReadWriteOptions): number
truncate(newSize: number): Promise<void>
flush(): Promise<void>
close(): Promise<void>
}
Expand Down

0 comments on commit e97f513

Please sign in to comment.