Skip to content

Commit

Permalink
feat: add file.getOriginFile
Browse files Browse the repository at this point in the history
  • Loading branch information
hughfenghen committed Jul 8, 2024
1 parent 5514e58 commit 3735a5f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/silent-beans-whisper.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'opfs-tools': patch
---

feat: add file.getOriginFile
13 changes: 10 additions & 3 deletions src/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,15 +213,22 @@ export class OPFSFileWrap {
}

async stream() {
const fh = await getFSHandle(this.#path, { create: false, isFile: true });
if (fh == null) {
const ofile = await this.getOriginFile();
if (ofile == null) {
return new ReadableStream<Uint8Array>({
pull: (ctrl) => {
ctrl.close();
},
});
}
return (await fh.getFile()).stream();

return ofile.stream();
}

async getOriginFile() {
return (
await getFSHandle(this.#path, { create: false, isFile: true })
)?.getFile();
}

async getSize() {
Expand Down

0 comments on commit 3735a5f

Please sign in to comment.