Skip to content

Commit

Permalink
Impliment llseek for the /dev/blob device enabling loading larger fil…
Browse files Browse the repository at this point in the history
…es (#159)
  • Loading branch information
samwillis authored Aug 10, 2024
1 parent 1f6708a commit c1dfe9c
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions packages/pglite/src/pglite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,9 @@ export class PGlite implements PGliteInterface, AsyncDisposable {
) => {
const buf = this.#queryReadBuffer
if (!buf) {
throw new Error('No File or Blob provided to read from')
throw new Error(
'No /deb/blob File or Blob provided to read from',
)
}
const contents = new Uint8Array(buf)
if (position >= contents.length) return 0
Expand All @@ -204,8 +206,21 @@ export class PGlite implements PGliteInterface, AsyncDisposable {
this.#queryWriteChunks.push(buffer.slice(offset, offset + length))
return length
},
llseek: (_stream: any, _offset: number, _whence: number) => {
throw new Error('Cannot seek /dev/blob')
llseek: (stream: any, offset: number, whence: number) => {
const buf = this.#queryReadBuffer
if (!buf) {
throw new Error('No /dev/blob File or Blob provided to llseek')
}
var position = offset
if (whence === 1) {
position += stream.position
} else if (whence === 2) {
position = new Uint8Array(buf).length
}
if (position < 0) {
throw new mod.FS.ErrnoError(28)
}
return position
},
}
mod.FS.registerDevice(devId, devOpt)
Expand Down

0 comments on commit c1dfe9c

Please sign in to comment.